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. arcnetE_init
  6. arcnet_open
  7. arcnet_close
  8. arcnetA_send_packet
  9. arcnetA_continue_tx
  10. arcnetA_prepare_tx
  11. arcnetA_go_tx
  12. arcnetE_send_packet
  13. arcnet_interrupt
  14. arcnet_inthandler
  15. arcnet_rx
  16. arcnetA_rx
  17. arcnetE_rx
  18. arcnet_get_stats
  19. set_multicast_list
  20. arcnetA_header
  21. arcnetA_rebuild_header
  22. arcnetA_type_trans
  23. init_module
  24. cleanup_module

   1 /* arcnet.c
   2         Written 1994-95 by Avery Pennarun, derived from skeleton.c by
   3         Donald 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         v1.93 ALPHA (95/08/10)
  21           - Should work with both 1.2.x and 1.3.x now. (I hope)
  22           - Renamed arc0w ("Windows" protocol) to arc0e ("Ethernet-Encap")
  23             because the protocol used isn't necessarily limited to
  24             Microsoft.
  25 
  26         v1.92 ALPHA (95/07/11)
  27           - Fixes to make things work with kernel 1.3.x.  Completely broke
  28             1.2.x support.  Oops?  1.2.x users keep using 1.91 ALPHA until I
  29             get out a version that supports both.
  30 
  31         v1.91 ALPHA (95/07/02)
  32           - Oops.  Exception packets hit us again!  I remembered to test
  33             them in ethernet-protocol mode, but due to the many various
  34             changes they broke in RFC1201 instead.  All fixed.
  35           - A long-standing bug with "exception" packets not setting
  36             protocol_id properly has been corrected.  This would have caused
  37             random problems talking to non-Linux servers.  I've also sent in
  38             a patch to fix this in the latest stable ARCnet (now 1.02).
  39           - ARC_P_IPX is an RFC1201 protocol too.  Thanks, Tomasz.
  40           - We're now "properly" (I think) handling the multiple 'tbusy' and
  41             'start' flags (one for each protocol device) better.
  42           - The driver should now start without a NULL-pointer dereference
  43             if you aren't connected to the network.
  44           
  45         v1.90 ALPHA (95/06/18)
  46           - Removal of some outdated and messy config options (no one has
  47             ever complained about the defaults since they were introduced):
  48             DANGER_PROBE, EXTRA_DELAYS, IRQ_XMIT, CAREFUL_XMIT,
  49             STRICT_MEM_DETECT, LIMIT_MTU, USE_TIMER_HANDLER.  Also took out
  50             a few "#if 0" sections which are no longer useful.
  51           - Cleaned up debug levels - now instead of levels, there are
  52             individual flags.  Watch out when changing with ifconfig.
  53           - More cleanups and beautification.  Removed more dead code and
  54             made sure every function was commented.
  55           - Fixed the DETECT_RECONFIGS option so that it actually _won't_
  56             detect reconfigs.  Previously, the RECON irq would be disabled
  57             but the recon messages would still be logged on the next normal
  58             IRQ.
  59           - Initial support for "multiprotocol" ARCnet (this involved a LOT
  60             of reorganizing!).  Added an arc0w device, which allows us to
  61             talk to ethernet-over-ARCnet TCP/IP protocol.  To use it, ifconfig
  62             arc0 and arc0w (in that order).  For now, ethernet-protocol
  63             hosts should have routes through arc0w - eventually I hope to
  64             make things more automatic.
  65         v1.11 ALPHA (95/06/07)
  66           - Tomasz saves the day again with patches to fix operation if the
  67             new VERIFY_ACK option is disabled.
  68           - LOTS of little code cleanups/improvements by Tomasz.
  69           - Changed autoprobe, since the "never-changing command port"
  70             probe was causing problems for some people.  I also reset the
  71             card fewer times during the probe if DANGER_PROBE is defined,
  72             since DANGER_PROBE seems to be a more reliable method anyway.
  73           - It looks like the null-pointer problem was finally REALLY fixed
  74             by some change from Linux 1.2.8 to 1.2.9.  How handy!
  75         v1.10 ALPHA (95/04/15)
  76           - Fixed (?) some null-pointer dereference bugs
  77           - Added better network error detection (from Tomasz) - in
  78             particular, we now notice when our network isn't connected,
  79             also known as a "network reconfiguration."
  80           - We now increment lp->stats.tx_dropped in several more places,
  81             on a suggestion from Tomasz.
  82           - Minor cleanups/spelling fixes.
  83           - We now monitor the TXACK bit in the status register: we don't do
  84             anything with it yet, just notice when a transmitted packet isn't
  85             acknowledged.
  86           - Minor fix with sequence numbers (sometimes they were being sent in
  87             the wrong order due to Linux's packet queuing).
  88         v1.01 (95/03/24)
  89           - Fixed some IPX-related bugs. (Thanks to Tomasz Motylewski
  90             <motyl@tichy.ch.uj.edu.pl> for the patches to make arcnet work
  91             with dosemu!)
  92         v1.00 (95/02/15)
  93           - Initial non-alpha release.
  94         
  95          
  96         TO DO:
  97         
  98          - Test in systems with NON-ARCnet network cards, just to see if
  99            autoprobe kills anything.  Currently, we do cause some NE2000's to
 100            die.
 101          - What about cards with shared memory that can be "turned off?"
 102          - NFS mount freezes after several megabytes to SOSS for DOS. 
 103            unmount/remount fixes it.  Is this arcnet-specific?  I don't know.
 104          - Add support for "old" (RFC1051) protocol arcnet, such as AmiTCP
 105            and NetBSD.  Work in Tomasz' initial support for this.
 106          - How about TCP/IP over netbios?
 107          - Some newer ARCnets support promiscuous mode, supposedly. 
 108            If someone sends me information, I'll try to implement it.
 109          - Remove excess lock variables that are probably not necessary
 110            anymore due to the changes in Linux 1.2.9.
 111          - Dump Linux 1.2 and properly use the extended 1.3.x skb functions.
 112          - Problems forwarding from arc0e to arc0 in 1.3.x? (it may be a
 113            general kernel bug, though, since I heard other people complaining
 114            about forwarding problems on ethernet cards)
 115          - D_SKB doesn't work right on 1.3.x kernels.
 116 
 117            
 118         Sources:
 119          - Crynwr arcnet.com/arcether.com packet drivers.
 120          - arcnet.c v0.00 dated 1/1/94 and apparently by
 121                 Donald Becker - it didn't work :)
 122          - skeleton.c v0.05 dated 11/16/93 by Donald Becker
 123                 (from Linux Kernel 1.1.45)
 124          - The official ARCnet data sheets (!) thanks to Ken Cornetet
 125                 <kcornete@nyx10.cs.du.edu>
 126          - RFC's 1201 and 1051 (mostly 1201) - re: ARCnet IP packets
 127          - net/inet/eth.c (from kernel 1.1.50) for header-building info...
 128          - Alternate Linux ARCnet source by V.Shergin <vsher@sao.stavropol.su>
 129          - Textual information and more alternate source from Joachim Koenig
 130                 <jojo@repas.de>
 131 */
 132 
 133 static const char *version =
 134  "arcnet.c:v1.93 ALPHA 95/08/10 Avery Pennarun <apenwarr@foxnet.net>\n";
 135 
 136 /**************************************************************************/
 137 
 138 /* Define this if you want to detect network reconfigurations.
 139  * They may be a real nuisance on a larger ARCnet network: but if you are
 140  * a network administrator you probably would like to count them. 
 141  * Reconfigurations will be recorded in stats.tx_carrier_errors 
 142  * (the last field of the /proc/net/dev file).
 143  *
 144  * The card sends the reconfiguration signal when it loses the connection
 145  * to the rest of its network. It is a 'Hello, is anybody there?' cry.  This
 146  * usually happens when a new computer on the network is powered on or when
 147  * the cable is broken.
 148  */
 149 #define DETECT_RECONFIGS
 150 
 151 /* Define this if you want to make sure transmitted packets are "acknowledged"
 152  * by the destination host, as long as they're not to the broadcast address.
 153  *
 154  * That way, if one segment of a split packet doesn't get through, it can
 155  * be resent immediately rather than confusing the other end.
 156  *
 157  * Disable this to return to 1.01-style behaviour, if you have problems.
 158  */
 159 #define VERIFY_ACK
 160 
 161 /* Define this if you want to make it easier to use the "call trace" when
 162  * a kernel NULL pointer assignment occurs.
 163  */
 164 #undef static
 165 
 166 /**************************************************************************/
 167  
 168 
 169 #include <linux/config.h>
 170 #include <linux/version.h>
 171 
 172 #ifdef MODULE
 173 #include <linux/module.h>
 174 #endif /* MODULE */
 175 
 176 
 177 /* are we Linux 1.2.x? */
 178 #if LINUX_VERSION_CODE < 0x10300
 179 #define LINUX12
 180 #endif
 181 
 182 
 183 #include <linux/kernel.h>
 184 #include <linux/sched.h>
 185 #include <linux/types.h>
 186 #include <linux/fcntl.h>
 187 #include <linux/interrupt.h>
 188 #include <linux/ptrace.h>
 189 #include <linux/ioport.h>
 190 #include <linux/in.h>
 191 #include <linux/malloc.h>
 192 #include <linux/string.h>
 193 #include <linux/timer.h>
 194 #include <linux/errno.h>
 195 #include <linux/delay.h>
 196 
 197 #include <asm/system.h>
 198 #include <asm/bitops.h>
 199 #include <asm/io.h>
 200 #include <asm/dma.h>
 201 
 202 #include <linux/netdevice.h>
 203 #include <linux/etherdevice.h>
 204 #include <linux/skbuff.h>
 205 
 206 #include <net/arp.h>
 207 
 208 
 209 /* new debugging bitflags: each option can be enabled individually.
 210  *
 211  * these can be set while the driver is running by typing:
 212  *      ifconfig arc0 down metric 1xxx HOSTNAME
 213  *              where 1xx is 1000 + the debug level you want
 214  *              and HOSTNAME is your hostname/ip address
 215  * and then resetting your routes.
 216  */
 217 #define D_NORMAL        1       /* D_NORMAL  startup announcement       */
 218 #define D_INIT          2       /* D_INIT    show init/probe messages   */
 219 #define D_EXTRA         4       /* D_EXTRA   extra information          */
 220 /* debug levels past this point give LOTS of output! */
 221 #define D_DURING        8       /* D_DURING  during normal use (irq's)  */
 222 #define D_TX            16      /* D_TX      show tx packets            */
 223 #define D_RX            32      /* D_RX      show rx packets            */
 224 #define D_SKB           64      /* D_SKB     dump skb's                 */
 225 
 226 #ifndef NET_DEBUG
 227 #define NET_DEBUG D_NORMAL|D_INIT|D_EXTRA
 228 #endif
 229 int arcnet_debug = NET_DEBUG;
 230 
 231 #ifndef HAVE_AUTOIRQ
 232 /* From auto_irq.c, in ioport.h for later versions. */
 233 extern void autoirq_setup(int waittime);
 234 extern int autoirq_report(int waittime);
 235 /* The map from IRQ number (as passed to the interrupt handler) to
 236    'struct device'. */
 237 extern struct device *irq2dev_map[16];
 238 #endif
 239 
 240 #ifndef HAVE_PORTRESERVE
 241 #define check_region(ioaddr, size)              0
 242 #define request_region(ioaddr, size)            do ; while (0)
 243 #endif
 244 
 245 /* macro to simplify debug checking */
 246 #define BUGLVL(x) if (arcnet_debug&(x))
 247 
 248 
 249 /* Some useful multiprotocol macros */
 250 #define TBUSY lp->adev->tbusy \
 251                 =lp->edev->tbusy
 252 #define IF_TBUSY (lp->adev->tbusy \
 253                 || lp->edev->tbusy)
 254 #define START lp->adev->start \
 255                 =lp->edev->start
 256 
 257 
 258 /* The number of low I/O ports used by the ethercard. */
 259 #define ARCNET_TOTAL_SIZE       16
 260 
 261 
 262 /* Handy defines for ARCnet specific stuff */
 263         /* COM 9026 (?) --> ARCnet register addresses */
 264 #define INTMASK (ioaddr+0)              /* writable */
 265 #define STATUS  (ioaddr+0)              /* readable */
 266 #define COMMAND (ioaddr+1)      /* writable, returns random vals on read (?) */
 267 #define RESET  (ioaddr+8)               /* software reset writable */
 268 
 269         /* Time needed for various things (in clock ticks, 1/100 sec) */
 270         /* We mostly don't bother with these - watch out. */
 271 #define RESETtime 40            /* reset */
 272 #define XMITtime 10             /* send (?) */
 273 #define ACKtime 10              /* acknowledge (?) */
 274 
 275         /* these are the max/min lengths of packet data. (including
 276          * ClientData header)
 277          * note: packet sizes 250, 251, 252 are impossible (God knows why)
 278          *  so exception packets become necessary.
 279          *
 280          * These numbers are compared with the length of the full packet,
 281          * including ClientData header.
 282          */
 283 #define MTU     253     /* normal packet max size */
 284 #define MinTU   257     /* extended packet min size */
 285 #define XMTU    508     /* extended packet max size */
 286 
 287         /* status/interrupt mask bit fields */
 288 #define TXFREEflag      0x01            /* transmitter available */
 289 #define TXACKflag       0x02            /* transmitted msg. ackd */
 290 #define RECONflag       0x04            /* system reconfigured */
 291 #define TESTflag        0x08            /* test flag */
 292 #define RESETflag       0x10            /* power-on-reset */
 293 #define RES1flag        0x20            /* unused */
 294 #define RES2flag        0x40            /* unused */
 295 #define NORXflag        0x80            /* receiver inhibited */
 296 
 297 #ifdef DETECT_RECONFIGS
 298         #define RECON_flag RECONflag
 299 #else
 300         #define RECON_flag 0
 301 #endif
 302 
 303        /* in the command register, the following bits have these meanings:
 304         *                0-2     command
 305         *                3-4     page number (for enable rcv/xmt command)
 306         *                 7      receive broadcasts
 307         */
 308 #define NOTXcmd         0x01            /* disable transmitter */
 309 #define NORXcmd         0x02            /* disable receiver */
 310 #define TXcmd           0x03            /* enable transmitter */
 311 #define RXcmd           0x04            /* enable receiver */
 312 #define CONFIGcmd       0x05            /* define configuration */
 313 #define CFLAGScmd       0x06            /* clear flags */
 314 #define TESTcmd         0x07            /* load test flags */
 315 
 316        /* flags for "clear flags" command */
 317 #define RESETclear      0x08            /* power-on-reset */
 318 #define CONFIGclear     0x10            /* system reconfigured */
 319 
 320       /* flags for "load test flags" command */
 321 #define TESTload        0x08            /* test flag (diagnostic) */
 322 
 323       /* byte deposited into first address of buffers on reset */
 324 #define TESTvalue       0321             /* that's octal for 0xD1 :) */
 325 
 326       /* for "enable receiver" command */
 327 #define RXbcasts        0x80            /* receive broadcasts */
 328 
 329       /* flags for "define configuration" command */
 330 #define NORMALconf      0x00            /* 1-249 byte packets */
 331 #define EXTconf         0x08            /* 250-504 byte packets */
 332 
 333         /* buffers (4 total) used for receive and xmit.
 334          */
 335 #define EnableReceiver()        outb(RXcmd|(recbuf<<3)|RXbcasts,COMMAND)
 336 
 337         /* RFC1201 Protocol ID's */
 338 #define ARC_P_IP        212             /* 0xD4 */
 339 #define ARC_P_ARP       213             /* 0xD5 */
 340 #define ARC_P_RARP      214             /* 0xD6 */
 341 #define ARC_P_IPX       250             /* 0xFA */
 342 
 343         /* MS LanMan/WfWg protocol */
 344 #define ARC_P_MS_TCPIP  0xE8
 345 
 346         /* Unsupported/indirectly supported protocols */
 347 #define ARC_P_LANSOFT   251             /* 0xFB */
 348 #define ARC_P_ATALK     0xDD
 349 
 350         /* these structures define the format of an arcnet packet. */
 351 #define NORMAL          0
 352 #define EXTENDED        1
 353 #define EXCEPTION       2
 354 
 355         /* the header required by the card itself */
 356 struct HardHeader
 357 {
 358         u_char  source,         /* source ARCnet - filled in automagically */
 359                 destination,    /* destination ARCnet - 0 for broadcast */
 360                 offset1,        /* offset of ClientData (256-byte packets) */
 361                 offset2;        /* offset of ClientData (512-byte packets) */
 362 };
 363 
 364         /* a complete ARCnet packet */
 365 union ArcPacket
 366 {
 367         struct HardHeader hardheader;   /* the hardware header */
 368         u_char raw[512];                /* raw packet info, incl ClientData */
 369 };
 370 
 371         /* the "client data" header - RFC-1201 information
 372          * notice that this screws up if it's not an even number of bytes
 373          * <sigh>
 374          */
 375 struct ClientData
 376 {
 377         /* data that's NOT part of real packet - we MUST get rid of it before
 378          * actually sending!!
 379          */
 380         u_char  saddr,          /* Source address - needed for IPX */
 381                 daddr;          /* Destination address */
 382         
 383         /* data that IS part of real packet */
 384         u_char  protocol_id,    /* ARC_P_IP, ARC_P_ARP, etc */
 385                 split_flag;     /* for use with split packets */
 386         u_short sequence;       /* sequence number */
 387 };
 388 #define EXTRA_CLIENTDATA (sizeof(struct ClientData)-4)
 389 
 390 
 391 /* "Incoming" is information needed for each address that could be sending
 392  * to us.  Mostly for partially-received split packets.
 393  */
 394 struct Incoming
 395 {
 396         struct sk_buff *skb;            /* packet data buffer             */
 397         unsigned char lastpacket,       /* number of last packet (from 1) */
 398                       numpackets;       /* number of packets in split     */
 399         u_short sequence;               /* sequence number of assembly    */
 400 };
 401 
 402 struct Outgoing
 403 {
 404         struct sk_buff *skb;            /* buffer from upper levels */
 405         struct ClientData *hdr;         /* clientdata of last packet */
 406         u_char *data;                   /* pointer to data in packet */
 407         short length,                   /* bytes total */
 408               dataleft,                 /* bytes left */
 409               segnum,                   /* segment being sent */
 410               numsegs,                  /* number of segments */
 411               seglen;                   /* length of segment */
 412 #ifdef VERIFY_ACK
 413         short lastload_dest,            /* can last loaded packet be acked? */
 414               lasttrans_dest;           /* can last TX'd packet be acked? */
 415 #endif
 416         
 417 };
 418 
 419 
 420 /* Information that needs to be kept for each board. */
 421 struct arcnet_local {
 422         struct enet_statistics stats;
 423         u_char arcnum;          /* arcnet number - our 8-bit address */
 424         u_short sequence;       /* sequence number (incs with each packet) */
 425         u_char recbuf,          /* receive buffer # (0 or 1) */
 426                txbuf,           /* transmit buffer # (2 or 3) */
 427                txready;         /* buffer where a packet is ready to send */
 428         short intx,             /* in TX routine? */
 429               in_txhandler,     /* in TX_IRQ handler? */
 430               sending;          /* transmit in progress? */
 431         short tx_left;          /* segments of split packet left to TX */
 432         
 433         struct timer_list timer; /* the timer interrupt struct */
 434         struct Incoming incoming[256];  /* one from each address */
 435         struct Outgoing outgoing; /* packet currently being sent */
 436         
 437         struct device *adev;    /* RFC1201 protocol device */
 438         struct device *edev;    /* Ethernet-Encap device */
 439 };
 440 
 441 
 442 /* Index to functions, as function prototypes. */
 443 extern int arcnet_probe(struct device *dev);
 444 #ifndef MODULE
 445 static int arcnet_memprobe(struct device *dev,u_char *addr);
 446 static int arcnet_ioprobe(struct device *dev, short ioaddr);
 447 #endif
 448 static int arcnetE_init(struct device *dev);
 449 
 450 static int arcnet_open(struct device *dev);
 451 static int arcnet_close(struct device *dev);
 452 static int arcnet_reset(struct device *dev);
 453 
 454 static int arcnetA_send_packet(struct sk_buff *skb, struct device *dev);
 455 static void arcnetA_continue_tx(struct device *dev);
 456 static void arcnetA_prepare_tx(struct device *dev,struct ClientData *hdr,
 457                 short length,char *data);
 458 static void arcnetA_go_tx(struct device *dev);
 459 
 460 static int arcnetE_send_packet(struct sk_buff *skb, struct device *dev);
 461 
 462 static void arcnet_interrupt(int irq,struct pt_regs *regs);
 463 static void arcnet_inthandler(struct device *dev);
 464 
 465 static void arcnet_rx(struct device *dev,int recbuf);
 466 static void arcnetA_rx(struct device *dev,struct ClientData *arcsoft,
 467         int length,u_char saddr, u_char daddr);
 468 static void arcnetE_rx(struct device *dev,u_char *arcsoft,
 469         int length,u_char saddr, u_char daddr);
 470 
 471 static struct enet_statistics *arcnet_get_stats(struct device *dev);
 472 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
 473 
 474         /* functions for header/arp/etc building */
 475 #ifdef LINUX12
 476 int arcnetA_header(unsigned char *buff,struct device *dev,
 477                 unsigned short type,void *daddr,void *saddr,unsigned len,
 478                 struct sk_buff *skb);
 479 #else
 480 int arcnetA_header(struct sk_buff *skb,struct device *dev,
 481                 unsigned short type,void *daddr,void *saddr,unsigned len);
 482 #endif
 483 int arcnetA_rebuild_header(void *eth,struct device *dev,unsigned long raddr,
 484                 struct sk_buff *skb);
 485 unsigned short arcnetA_type_trans(struct sk_buff *skb,struct device *dev);
 486 
 487 #ifdef MODULE
 488 int  init_module(void);
 489 void cleanup_module(void);
 490 #endif
 491 
 492 #define tx_done(dev) 1
 493 
 494 #define JIFFER(time) for (delayval=0; delayval<(time*10); delayval++) \
 495                 udelay(1000);
 496                 
 497 
 498 /****************************************************************************
 499  *                                                                          *
 500  * Probe and initialization                                                 *
 501  *                                                                          *
 502  ****************************************************************************/
 503  
 504 
 505 /* Check for a network adaptor of this type, and return '0' if one exists.
 506  *  If dev->base_addr == 0, probe all likely locations.
 507  *  If dev->base_addr == 1, always return failure.
 508  *  If dev->base_addr == 2, allocate space for the device and return success
 509  *  (detachable devices only).
 510  */
 511 int
 512 arcnet_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 513 {
 514 #ifndef MODULE
 515         /* I refuse to probe anything less than 0x200, because anyone using
 516          * an address like that should probably be shot.
 517          */
 518         int *port, ports[] = {/* first the suggested values! */
 519                               0x300,0x2E0,0x2F0,0x2D0,
 520                               /* ...now everything else possible. */
 521                               0x200,0x210,0x220,0x230,0x240,0x250,0x260,0x270,
 522                               0x280,0x290,0x2a0,0x2b0,0x2c0,
 523                                     0x310,0x320,0x330,0x340,0x350,0x360,0x370,
 524                               0x380,0x390,0x3a0,/* video ports, */0x3e0,0x3f0,
 525                               /* a null ends the list */
 526                               0};
 527         /* I'm not going to probe below 0xA0000 either, for similar reasons.
 528          */
 529         unsigned long *addr, addrs[] = {0xD0000,0xE0000,0xA0000,0xB0000,
 530                                         0xC0000,0xF0000,
 531                                         /* from <mdrejhon@magi.com> */
 532                                         0xE1000,
 533                                         0xDD000,0xDC000,
 534                                         0xD9000,0xD8000,0xD5000,0xD4000,0xD1000,
 535                                         0xCD000,0xCC000,
 536                                         0xC9000,0xC8000,0xC5000,0xC4000,
 537                                         /* terminator */
 538                                         0};
 539         int base_addr=dev->base_addr, status=0;
 540 #endif /* MODULE */
 541         int delayval;
 542         struct arcnet_local *lp;
 543 
 544         BUGLVL(D_NORMAL)
 545         {
 546                 printk(version);
 547                 printk("arcnet: ***\n");
 548                 printk("arcnet: * Read linux/drivers/net/README.arcnet for important release notes!\n");
 549                 printk("arcnet: *\n");
 550                 printk("arcnet: * This is an ALPHA version!  (Last stable release: v1.02)  E-mail me if\n");
 551                 printk("arcnet: * you have any questions, comments, or bug reports.\n");
 552                 printk("arcnet: ***\n");
 553         }
 554 
 555         BUGLVL(D_INIT)
 556                 printk("arcnet: given: base %lXh, IRQ %Xh, shmem %lXh\n",
 557                         dev->base_addr,dev->irq,dev->mem_start);
 558                         
 559 #ifndef MODULE
 560         if (base_addr > 0x1ff)          /* Check a single specified location. */
 561                 status=arcnet_ioprobe(dev, base_addr);
 562         else if (base_addr > 0)         /* Don't probe at all. */
 563                 return ENXIO;
 564         else for (port = &ports[0]; *port; port++)
 565         {
 566                 int ioaddr = *port;
 567                 if (check_region(ioaddr, ARCNET_TOTAL_SIZE))
 568                 {
 569                         BUGLVL(D_INIT)
 570                                 printk("arcnet: Skipping %Xh because of check_region...\n",
 571                                         ioaddr);
 572                         continue;
 573                 }
 574 
 575                 status=arcnet_ioprobe(dev, ioaddr);
 576                 if (!status) break;
 577         }
 578         
 579         if (status) return status;
 580 
 581         /* ioprobe turned out okay.  Now give it a couple seconds to finish
 582          * initializing...
 583          */
 584         BUGLVL(D_INIT)
 585                 printk("arcnet: ioprobe okay!  Waiting for reset...\n");
 586         JIFFER(100);
 587 
 588         /* okay, now we have to find the shared memory area. */
 589         BUGLVL(D_INIT)
 590                 printk("arcnet: starting memory probe, given %lXh\n",
 591                         dev->mem_start);
 592         if (dev->mem_start)     /* value given - probe just that one */
 593         {
 594                 status=arcnet_memprobe(dev,(u_char *)dev->mem_start);
 595                 if (status) return status;
 596         }
 597         else                    /* no value given - probe everything */
 598         {
 599                 for (addr = &addrs[0]; *addr; addr++) {
 600                         status=arcnet_memprobe(dev,(u_char *)(*addr));
 601                         if (!status) break;
 602                 }
 603                 
 604                 if (status) return status;
 605         }
 606 #else /* MODULE */
 607         if (!dev->base_addr || !dev->irq || !dev->mem_start 
 608                 || !dev->rmem_start)
 609         {
 610                 printk("arcnet: loadable modules can't autoprobe!\n");
 611                 printk("arcnet:  try using io=, irqnum=, and shmem= on the insmod line.\n");
 612                 printk("arcnet:  you may also need num= to change the device name. (ie. num=1 for arc1)\n");
 613                 return ENODEV;
 614         }
 615 #endif
 616         /* now reserve the irq... */
 617         {       
 618                 int irqval = request_irq(dev->irq, &arcnet_interrupt, 0,
 619                         "arcnet");
 620                 if (irqval) {
 621                         printk("%s: unable to get IRQ %d (irqval=%d).\n",
 622                                 dev->name,dev->irq, irqval);
 623                         return EAGAIN;
 624                  }
 625          }
 626          
 627         /* Grab the region so we can find another board if autoIRQ fails. */
 628         request_region(dev->base_addr, ARCNET_TOTAL_SIZE,"arcnet");
 629         
 630         printk("%s: ARCnet card found at %03lXh, IRQ %d, ShMem at %lXh.\n", 
 631                 dev->name, dev->base_addr, dev->irq, dev->mem_start);
 632 
 633         /* Initialize the device structure. */
 634         dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
 635         memset(dev->priv, 0, sizeof(struct arcnet_local));
 636         lp=(struct arcnet_local *)(dev->priv);
 637 
 638         dev->open=arcnet_open;
 639         dev->stop=arcnet_close;
 640         dev->hard_start_xmit=arcnetA_send_packet;
 641         dev->get_stats=arcnet_get_stats;
 642 #ifdef HAVE_MULTICAST
 643         dev->set_multicast_list = &set_multicast_list;
 644 #endif
 645 
 646         /* Fill in the fields of the device structure with ethernet-generic
 647          * values.
 648          */
 649         ether_setup(dev);
 650         
 651         /* And now fill particular fields with arcnet values */
 652         dev->type=ARPHRD_ARCNET;
 653         dev->hard_header_len=sizeof(struct ClientData);
 654         BUGLVL(D_DURING)
 655                 printk("arcnet: ClientData header size is %d.\narcnet: HardHeader size is %d.\n",
 656                         sizeof(struct ClientData),sizeof(struct HardHeader));
 657 
 658                 /* since we strip EXTRA_CLIENTDATA bytes off before sending,
 659                  * we let Linux add that many bytes to the packet data...
 660                  */
 661         dev->addr_len=1;
 662         dev->broadcast[0]=0x00;
 663         
 664         BUGLVL(D_INIT) printk("arcnet: arcnet_probe: resetting card.\n");
 665         arcnet_reset(dev);
 666         JIFFER(50);
 667         BUGLVL(D_NORMAL)
 668                 printk("arcnet: We appear to be station %d (%02Xh)\n",
 669                         lp->arcnum,lp->arcnum);
 670         if (lp->arcnum==0)
 671                 printk("arcnet: WARNING!  Station address 0 is reserved for broadcasts!\n");
 672         if (lp->arcnum==255)
 673                 printk("arcnet: WARNING!  Station address 255 may confuse DOS networking programs!\n");
 674         dev->dev_addr[0]=lp->arcnum;
 675         lp->sequence=1;
 676         lp->recbuf=0;
 677 
 678         dev->hard_header=arcnetA_header;
 679         dev->rebuild_header=arcnetA_rebuild_header;
 680         
 681         #ifdef LINUX12
 682         dev->type_trans=arcnetA_type_trans;
 683         #endif
 684 
 685         return 0;
 686 }
 687 
 688 #ifndef MODULE
 689 
 690 int arcnet_ioprobe(struct device *dev, short ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 691 {
 692         int delayval,airq;
 693 
 694         BUGLVL(D_INIT)
 695         {
 696                 printk("arcnet: probing address %Xh\n",ioaddr);
 697                 printk("arcnet:  status1=%Xh\n",inb(STATUS));
 698         }
 699 
 700                 
 701         /* very simple - all we have to do is reset the card, and if there's
 702          * no irq, it's not an ARCnet.  We can also kill two birds with
 703          * one stone because we detect the IRQ at the same time :)
 704          */
 705          
 706         /* reset the card by reading the reset port */
 707         inb(RESET);
 708         JIFFER(RESETtime);
 709 
 710         /* if status port is FF, there's certainly no arcnet... give up. */
 711         if (inb(STATUS)==0xFF)
 712         {
 713                 BUGLVL(D_INIT)
 714                         printk("arcnet:  probe failed.  Status port empty.\n");
 715                 return ENODEV;
 716         }
 717 
 718 #if 0
 719         /* we'll try to be reasonably sure it's an arcnet by making sure
 720          * the value of the COMMAND port changes automatically once in a
 721          * while.  I have no idea what those values ARE, but at least
 722          * they work.
 723          */
 724         {
 725                 int initval,curval;
 726                 
 727                 curval=initval=inb(COMMAND);
 728                 delayval=jiffies+5;
 729                 while (delayval>=jiffies && curval==initval)
 730                         curval=inb(COMMAND);
 731                         
 732                 if (curval==initval)
 733                 {
 734                         printk("arcnet:  probe failed.  never-changing command port (%02Xh).\n",
 735                                 initval);
 736                         return ENODEV;
 737                 }
 738         }
 739 #endif
 740 
 741         BUGLVL(D_INIT)
 742                 printk("arcnet:  status2=%Xh\n",inb(STATUS));
 743 
 744         /* now we turn the reset bit off so we can IRQ next reset... */
 745         outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
 746         if (inb(STATUS) & RESETflag) /* reset flag STILL on */
 747         {
 748                 BUGLVL(D_INIT)
 749                         printk("arcnet:  probe failed.  eternal reset flag1...(status=%Xh)\n",
 750                                 inb(STATUS));
 751                 return ENODEV;
 752         }
 753 
 754         /* set up automatic IRQ detection */
 755         autoirq_setup(0);
 756         
 757 
 758         /* if we do this, we're sure to get an IRQ since the card has
 759          * just reset and the NORXflag is on until we tell it to start
 760          * receiving.
 761          *
 762          * However, this could, theoretically, cause a lockup.  Maybe I'm just
 763          * not very good at theory! :)
 764          */
 765         outb(NORXflag,INTMASK);
 766         JIFFER(RESETtime);
 767         outb(0,INTMASK);
 768 
 769         /* and turn the reset flag back off */
 770         outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
 771 
 772         airq = autoirq_report(0);
 773         BUGLVL(D_INIT) if (airq)
 774                 printk("arcnet:  autoirq is %d\n", airq);
 775 
 776         /* if there was no autoirq AND the user hasn't set any defaults,
 777          * give up.
 778          */
 779         if (!airq && !(dev->base_addr && dev->irq))
 780         {
 781                 BUGLVL(D_INIT)
 782                         printk("arcnet:  probe failed.  no autoirq...\n");
 783                 return ENODEV;
 784         }
 785 
 786         /* otherwise we probably have a card.  Let's make sure. */
 787         
 788         if (inb(STATUS) & RESETflag) /* reset flag on */
 789         {
 790                 /* now we turn the reset bit off */
 791                 outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
 792         }
 793         
 794         if (inb(STATUS) & RESETflag) /* reset flag STILL on */
 795         {
 796                 BUGLVL(D_INIT)
 797                         printk("arcnet:  probe failed.  eternal reset flag...(status=%Xh)\n",
 798                                 inb(STATUS));
 799                 return ENODEV;
 800         }
 801         
 802         /* okay, we've got a real, live ARCnet on our hands. */
 803         if (!dev->base_addr) dev->base_addr=ioaddr;
 804         
 805         if (dev->irq < 2)               /* "Auto-IRQ" */
 806         {
 807                 /* we already did the autoirq above, so store the values */
 808                 dev->irq=airq;
 809         }
 810         else if (dev->irq == 2)
 811         {
 812                 BUGLVL(D_NORMAL)
 813                         printk("arcnet: IRQ2 == IRQ9, don't worry.\n");
 814                 dev->irq = 9;
 815         }
 816 
 817         BUGLVL(D_INIT)
 818                 printk("arcnet: irq and base address seem okay. (%lXh, IRQ %d)\n",
 819                         dev->base_addr,dev->irq);
 820         return 0;
 821 }
 822 
 823 
 824 /* A memory probe that is called after the card is reset.
 825  * It checks for the official TESTvalue in byte 0 and makes sure the buffer
 826  * has certain characteristics of an ARCnet.
 827  */
 828 int arcnet_memprobe(struct device *dev,u_char *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 829 {
 830         BUGLVL(D_INIT)
 831                 printk("arcnet: probing memory at %lXh\n",(u_long)addr);
 832                 
 833         dev->mem_start=0;
 834 
 835         /* ARCnet memory byte 0 is TESTvalue */
 836         if (addr[0]!=TESTvalue)
 837         {
 838                 BUGLVL(D_INIT)
 839                         printk("arcnet:  probe failed.  addr=%lXh, addr[0]=%Xh (not %Xh)\n",
 840                                 (unsigned long)addr,addr[0],TESTvalue);
 841                 return ENODEV;
 842         }
 843         
 844         /* now verify the shared memory writability */
 845         addr[0]=0x42;
 846         if (addr[0]!=0x42)
 847         {
 848                 BUGLVL(D_INIT)
 849                         printk("arcnet:  probe failed.  addr=%lXh, addr[0]=%Xh (not 42h)\n",
 850                                 (unsigned long)addr,addr[0]);
 851                 return ENODEV;
 852         }
 853 
 854         /* got it!  fill in dev */
 855         dev->mem_start=(unsigned long)addr;
 856         dev->mem_end=dev->mem_start+512*4-1;
 857         dev->rmem_start=dev->mem_start+512*0;
 858         dev->rmem_end=dev->mem_start+512*2-1;
 859 
 860         return 0;
 861 }
 862 
 863 #endif /* MODULE */
 864 
 865 
 866 int arcnet_reset(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 867 {
 868         struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
 869         short ioaddr=dev->base_addr;
 870         int delayval,recbuf=lp->recbuf;
 871         u_char *cardmem;
 872         
 873         outb(0,INTMASK);        /* no IRQ's, please! */
 874         
 875         BUGLVL(D_INIT)
 876                 printk("arcnet: Resetting %s (status=%Xh)\n",
 877                         dev->name,inb(STATUS));
 878 
 879         inb(RESET);             /* Reset by reading this port */
 880         JIFFER(RESETtime);
 881 
 882         outb(CFLAGScmd|RESETclear, COMMAND); /* clear flags & end reset */
 883         outb(CFLAGScmd|CONFIGclear,COMMAND);
 884 
 885         /* after a reset, the first byte of shared mem is TESTvalue and the
 886          * second byte is our 8-bit ARCnet address.
 887          */
 888         cardmem = (u_char *) dev->mem_start;
 889         if (cardmem[0] != TESTvalue)
 890         {
 891                 BUGLVL(D_INIT)
 892                         printk("arcnet: reset failed: TESTvalue not present.\n");
 893                 return 1;
 894         }
 895         lp->arcnum=cardmem[1];  /* save address for later use */
 896         
 897         /* clear out status variables */
 898         recbuf=lp->recbuf=0;
 899         lp->txbuf=2;
 900 
 901         /* enable extended (512-byte) packets */
 902         outb(CONFIGcmd|EXTconf,COMMAND);
 903         
 904         /* clean out all the memory to make debugging make more sense :) */
 905         BUGLVL(D_DURING)
 906                 memset((void *)dev->mem_start,0x42,2048);
 907         
 908         /* and enable receive of our first packet to the first buffer */
 909         EnableReceiver();
 910 
 911         /* re-enable interrupts */
 912         outb(NORXflag|RECON_flag,INTMASK);
 913         
 914         /* done!  return success. */
 915         return 0;
 916 }
 917 
 918 static int arcnetE_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 919 {
 920         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
 921 
 922         ether_setup(lp->edev);
 923         dev->dev_addr[0]=0;
 924         dev->dev_addr[5]=lp->arcnum;
 925         dev->mtu=493;   /* MTU is small because of missing packet splitting */
 926         lp->edev->open=NULL;
 927         lp->edev->stop=NULL;
 928         lp->edev->hard_start_xmit=arcnetE_send_packet;
 929 
 930         BUGLVL(D_EXTRA)
 931                 printk("%s: ARCnet \"Ethernet-Encap\" protocol initialized.\n",
 932                         lp->edev->name);
 933                         
 934         return 0;
 935 }
 936 
 937 
 938 /****************************************************************************
 939  *                                                                          *
 940  * Open and close the driver                                                *
 941  *                                                                          *
 942  ****************************************************************************/
 943  
 944 
 945 /* Open/initialize the board.  This is called sometime after booting when
 946  * the 'ifconfig' program is run.
 947  *
 948  * This routine should set everything up anew at each open, even
 949  * registers that "should" only need to be set once at boot, so that
 950  * there is non-reboot way to recover if something goes wrong.
 951  */
 952 static int
 953 arcnet_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 954 {
 955         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
 956 
 957         if (dev->metric>=1000)
 958         {
 959                 arcnet_debug=dev->metric-1000;
 960                 printk("arcnet: debug level set to %d\n",arcnet_debug);
 961                 dev->metric=1;
 962         }
 963 
 964         BUGLVL(D_NORMAL) printk(version);
 965 
 966         irq2dev_map[dev->irq] = dev;
 967 
 968         BUGLVL(D_EXTRA) printk("arcnet: arcnet_open: resetting card.\n");
 969         
 970         /* try to reset - twice if it fails the first time */
 971         if (arcnet_reset(dev) && arcnet_reset(dev))
 972                 return -ENODEV;
 973         
 974         dev->tbusy=0;
 975         dev->interrupt=0;
 976         lp->intx=0;
 977         lp->in_txhandler=0;
 978         
 979         /* The RFC1201 driver is the default - just store */
 980         lp->adev=dev;
 981         BUGLVL(D_EXTRA)
 982                 printk("%s:  ARCnet RFC1201 protocol initialized.\n",
 983                         lp->adev->name);
 984         
 985         /* Initialize the ethernet-encap protocol driver */
 986         lp->edev=(struct device *)kmalloc(sizeof(struct device),GFP_KERNEL);
 987         memcpy(lp->edev,dev,sizeof(struct device));
 988         lp->edev->name=(char *)kmalloc(10,GFP_KERNEL);
 989         sprintf(lp->edev->name,"%se",dev->name);
 990         lp->edev->init=arcnetE_init;
 991         register_netdev(lp->edev);
 992 
 993         /* we're started */
 994         START=1;
 995 
 996 #ifdef MODULE
 997         MOD_INC_USE_COUNT;
 998 #endif
 999                                         
1000         return 0;
1001 }
1002 
1003 
1004 /* The inverse routine to arcnet_open - shuts down the card.
1005  */
1006 static int
1007 arcnet_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1008 {
1009         int ioaddr = dev->base_addr;
1010         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1011 
1012         TBUSY=1;
1013         START=0;
1014         
1015         /* Flush the Tx and disable Rx here.     */
1016 
1017         outb(0,INTMASK);        /* no IRQ's */
1018         outb(NOTXcmd,COMMAND);  /* disable transmit */
1019         outb(NORXcmd,COMMAND);  /* disable receive */
1020         
1021         /* do NOT free lp->adev!!  It's static! */
1022         lp->adev=NULL;
1023         
1024         /* free the ethernet-encap protocol device */
1025         lp->edev->start=0;
1026         lp->edev->priv=NULL;
1027         unregister_netdev(lp->edev);
1028         kfree(lp->edev->name);
1029         kfree(lp->edev);
1030         lp->edev=NULL;
1031 
1032         /* Update the statistics here. */
1033         
1034 #ifdef MODULE
1035         MOD_DEC_USE_COUNT;
1036 #endif
1037 
1038         return 0;
1039 }
1040 
1041 
1042 
1043 /****************************************************************************
1044  *                                                                          *
1045  * Transmitter routines                                                     *
1046  *                                                                          *
1047  ****************************************************************************/
1048 
1049 
1050 /* Called by the kernel in order to transmit a packet.
1051  */
1052 static int
1053 arcnetA_send_packet(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1054 {
1055         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1056         int ioaddr=dev->base_addr;
1057 
1058         lp->intx++;
1059         
1060         BUGLVL(D_DURING)
1061                 printk("arcnet: transmit requested (status=%Xh, inTX=%d)\n",
1062                         inb(STATUS),lp->intx);
1063                         
1064         if (lp->in_txhandler)
1065         {
1066                 printk("arcnet: send_packet called while in txhandler!\n");
1067                 lp->intx--;
1068                 return 1;
1069         }
1070 
1071         if (IF_TBUSY)
1072         {
1073                 /* If we get here, some higher level has decided we are broken.
1074                    There should really be a "kick me" function call instead. */
1075                 int tickssofar = jiffies - dev->trans_start;
1076                 int recbuf=lp->recbuf;
1077                 int status=inb(STATUS);
1078                 
1079                 if (tickssofar < 5) 
1080                 {
1081                         BUGLVL(D_DURING)
1082                                 printk("arcnet: premature kickme! (status=%Xh ticks=%d o.skb=%ph numsegs=%d segnum=%d\n",
1083                                         status,tickssofar,lp->outgoing.skb,
1084                                         lp->outgoing.numsegs,
1085                                         lp->outgoing.segnum);
1086                         lp->intx--;
1087                         return 1;
1088                 }
1089 
1090                 BUGLVL(D_EXTRA)
1091                         printk("arcnet: transmit timed out (status=%Xh, inTX=%d, inTXh=%d, tickssofar=%d)\n",
1092                                 status,lp->intx,lp->in_txhandler,tickssofar);
1093                                 
1094                 lp->stats.tx_errors++;
1095 
1096                 /* Try to restart the adaptor. */
1097                 /*arcnet_reset(dev);*/
1098                 
1099                 outb(0,INTMASK);
1100                 if (status&NORXflag) EnableReceiver();
1101                 if (!(status&TXFREEflag)) outb(NOTXcmd,COMMAND);
1102                 dev->trans_start = jiffies;
1103 
1104                 if (lp->outgoing.skb)
1105                 {
1106                         dev_kfree_skb(lp->outgoing.skb,FREE_WRITE);
1107                         lp->stats.tx_dropped++;
1108                 }
1109                 lp->outgoing.skb=NULL;
1110 
1111                 TBUSY=0;
1112                 lp->intx--;
1113                 /*lp->intx=0;*/
1114                 /*lp->in_txhandler=0;*/
1115                 lp->txready=0;
1116                 lp->sending=0;
1117                 mark_bh(NET_BH);
1118 
1119                 outb(NORXflag|RECON_flag,INTMASK);
1120 
1121                 return 1;
1122         }
1123 
1124         /* If some higher layer thinks we've missed a tx-done interrupt
1125            we are passed NULL. Caution: dev_tint() handles the cli()/sti()
1126            itself. */
1127         if (skb == NULL) {
1128                 BUGLVL(D_NORMAL)
1129                         printk("arcnet: tx passed null skb (status=%Xh, inTX=%d, tickssofar=%ld)\n",
1130                                 inb(STATUS),lp->intx,jiffies-dev->trans_start);
1131                 dev_tint(dev);
1132                 lp->intx--;
1133                 return 0;
1134         }
1135         
1136         if (lp->txready)        /* transmit already in progress! */
1137         {
1138                 printk("arcnet: trying to start new packet while busy! (status=%Xh)\n",
1139                         inb(STATUS));
1140                 /*printk("arcnet: marking as not ready.\n");*/
1141                 outb(0,INTMASK);
1142                 outb(NOTXcmd,COMMAND); /* abort current send */
1143                 arcnet_inthandler(dev); /* fake an interrupt */
1144                 lp->stats.tx_errors++;
1145                 lp->intx--;
1146                 lp->txready=0;  /* we definitely need this line! */
1147                 
1148                 return 1;
1149         }
1150 
1151         /* Block a timer-based transmit from overlapping.  This could better be
1152            done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
1153         if (set_bit(0, (void*)&dev->tbusy) != 0)
1154         {
1155             printk("arcnet: transmitter called with busy bit set! (status=%Xh, inTX=%d, tickssofar=%ld)\n",
1156                         inb(STATUS),lp->intx,jiffies-dev->trans_start);
1157             lp->intx--;
1158             return -EBUSY;
1159         }
1160         else {
1161                 struct Outgoing *out=&(lp->outgoing);
1162                 
1163                 TBUSY=1;
1164                 
1165                 out->length = 1 < skb->len ? skb->len : 1;
1166                 out->hdr=(struct ClientData*)skb->data;
1167                 out->skb=skb;
1168                 
1169                 BUGLVL(D_SKB)
1170                 {
1171                         short i;
1172                         for( i=0; i< skb->len; i++)
1173                         {
1174                                 if( i%16 == 0 ) printk("\n[%04hX] ",i);
1175                                 printk("%02hX ",((unsigned char*)skb->data)[i]);
1176                         }
1177                         printk("\n");
1178                 }
1179 
1180                 out->hdr->sequence=(lp->sequence++);
1181 
1182                 if (lp->txready && inb(STATUS)&TXFREEflag)
1183                         arcnetA_go_tx(dev);
1184                 
1185                 /* fits in one packet? */
1186                 if (out->length-EXTRA_CLIENTDATA<=XMTU)
1187                 {
1188                         BUGLVL(D_DURING)
1189                                 printk("arcnet: not splitting %d-byte packet. (split_flag=%d)\n",
1190                                         out->length,out->hdr->split_flag);
1191                         BUGLVL(D_EXTRA) if (out->hdr->split_flag)
1192                                 printk("arcnet: short packet has split_flag set?! (split_flag=%d)\n",
1193                                         out->hdr->split_flag);
1194                         out->numsegs=1;
1195                         out->segnum=1;
1196                         arcnetA_prepare_tx(dev,out->hdr,
1197                                 out->length-sizeof(struct ClientData),
1198                                 ((char *)skb->data)+sizeof(struct ClientData));
1199 
1200                         /* done right away */
1201                         dev_kfree_skb(out->skb,FREE_WRITE);
1202                         out->skb=NULL;
1203                                         
1204                         if (!lp->sending)
1205                         {
1206                                 arcnetA_go_tx(dev);
1207                                 
1208                                 /* inform upper layers */
1209                                 TBUSY=0;
1210                                 mark_bh(NET_BH);
1211                         }
1212                 }
1213                 else                    /* too big for one - split it */
1214                 {
1215                         int maxsegsize=XMTU-4;
1216 
1217                         out->data=(u_char *)skb->data
1218                                         + sizeof(struct ClientData);
1219                         out->dataleft=out->length-sizeof(struct ClientData);
1220                         out->numsegs=(out->dataleft+maxsegsize-1)/maxsegsize;
1221                                 
1222                         out->segnum=0;
1223                                 
1224                         BUGLVL(D_TX) printk("arcnet: packet (%d bytes) split into %d fragments:\n",
1225                                 out->length,out->numsegs);
1226 
1227                         /* if a packet waiting, launch it */
1228                         if (lp->txready && inb(STATUS)&TXFREEflag)
1229                                 arcnetA_go_tx(dev);
1230 
1231                         if (!lp->txready)
1232                         {
1233                                 /* prepare a packet, launch it and prepare
1234                                  * another.
1235                                  */
1236                                 arcnetA_continue_tx(dev);
1237                                 if (!lp->sending)
1238                                 {
1239                                         arcnetA_go_tx(dev);
1240                                         arcnetA_continue_tx(dev);
1241                                         if (!lp->sending)
1242                                                 arcnetA_go_tx(dev);
1243                                 }
1244                         }
1245                         
1246                         /* if segnum==numsegs, the transmission is finished;
1247                          * free the skb right away.
1248                          */
1249                         if (out->segnum==out->numsegs)
1250                         {
1251                                 /* transmit completed */
1252                                 out->segnum++;
1253                                 if (out->skb)
1254                                         dev_kfree_skb(out->skb,FREE_WRITE);
1255                                 out->skb=NULL;
1256                         }
1257                 }
1258         }
1259 
1260         lp->intx--;
1261         lp->stats.tx_packets++;
1262         dev->trans_start=jiffies;
1263         return 0;
1264 }
1265 
1266 /* After an RFC1201 split packet has been set up, this function calls
1267  * arcnetA_prepare_tx to load the next segment into the card.  This function
1268  * does NOT automatically call arcnetA_go_tx to allow for easier double-
1269  * buffering.
1270  */
1271 static void arcnetA_continue_tx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1272 {
1273         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1274         int maxsegsize=XMTU-4;
1275         struct Outgoing *out=&(lp->outgoing);
1276         
1277         if (lp->txready)
1278         {
1279                 printk("arcnet: continue_tx: called with packet in buffer!\n");
1280                 return;
1281         }
1282 
1283         if (out->segnum>=out->numsegs)
1284         {
1285                 printk("arcnet: continue_tx: building segment %d of %d!\n",
1286                         out->segnum+1,out->numsegs);
1287         }
1288 
1289         if (!out->segnum)       /* first packet */
1290                 out->hdr->split_flag=((out->numsegs-2)<<1)+1;
1291         else
1292                 out->hdr->split_flag=out->segnum<<1;
1293 
1294         out->seglen=maxsegsize;
1295         if (out->seglen>out->dataleft) out->seglen=out->dataleft;
1296                         
1297         BUGLVL(D_TX) printk("arcnet: building packet #%d (%d bytes) of %d (%d total), splitflag=%d\n",
1298                 out->segnum+1,out->seglen,out->numsegs,
1299                 out->length,out->hdr->split_flag);
1300 
1301         arcnetA_prepare_tx(dev,out->hdr,out->seglen,out->data);
1302                 
1303         out->dataleft-=out->seglen;
1304         out->data+=out->seglen;
1305         out->segnum++;
1306 }
1307 
1308 
1309 /* Given an skb, copy a packet into the ARCnet buffers for later transmission
1310  * by arcnetA_go_tx.
1311  */
1312 static void
1313 arcnetA_prepare_tx(struct device *dev,struct ClientData *hdr,short length,
     /* [previous][next][first][last][top][bottom][index][help] */
1314                 char *data)
1315 {
1316         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1317         struct ClientData *arcsoft;
1318         union ArcPacket *arcpacket = 
1319                 (union ArcPacket *)(dev->mem_start+512*(lp->txbuf^1));
1320         u_char pkttype;
1321         int offset;
1322         short daddr;
1323         
1324         lp->txbuf=lp->txbuf^1;  /* XOR with 1 to alternate between 2 and 3 */
1325         
1326         length+=4;
1327 
1328         BUGLVL(D_TX)
1329                 printk("arcnet: arcnetA_prep_tx: hdr:%ph, length:%d, data:%ph\n",
1330                         hdr,length,data);
1331 
1332         /* clean out the page to make debugging make more sense :) */
1333         BUGLVL(D_DURING)
1334                 memset((void *)dev->mem_start+lp->txbuf*512,0x42,512);
1335 
1336         daddr=arcpacket->hardheader.destination=hdr->daddr;
1337 
1338         /* load packet into shared memory */
1339         if (length<=MTU)        /* Normal (256-byte) Packet */
1340         {
1341                 pkttype=NORMAL;
1342                         
1343                 arcpacket->hardheader.offset1=offset=256-length;
1344                 arcsoft=(struct ClientData *)
1345                         (&arcpacket->raw[offset-EXTRA_CLIENTDATA]);
1346         }
1347         else if (length>=MinTU) /* Extended (512-byte) Packet */
1348         {
1349                 pkttype=EXTENDED;
1350                 
1351                 arcpacket->hardheader.offset1=0;
1352                 arcpacket->hardheader.offset2=offset=512-length;
1353                 arcsoft=(struct ClientData *)
1354                         (&arcpacket->raw[offset-EXTRA_CLIENTDATA]);
1355         }
1356         else                            /* Exception Packet */
1357         {
1358                 pkttype=EXCEPTION;
1359                 
1360                 arcpacket->hardheader.offset1=0;
1361                 arcpacket->hardheader.offset2=offset=512-length-4;
1362                 arcsoft=(struct ClientData *)
1363                         (&arcpacket->raw[offset+4-EXTRA_CLIENTDATA]);
1364                 
1365                 /* exception-specific stuff - these four bytes
1366                  * make the packet long enough to fit in a 512-byte
1367                  * frame.
1368                  */
1369                 arcpacket->raw[offset+0]=hdr->protocol_id;
1370                 arcpacket->raw[offset+1]=0xFF; /* FF flag */
1371                         arcpacket->raw[offset+2]=0xFF; /* FF padding */
1372                         arcpacket->raw[offset+3]=0xFF; /* FF padding */
1373         }
1374 
1375 
1376         /* copy the packet into ARCnet shmem
1377          *  - the first bytes of ClientData header are skipped
1378          */
1379         memcpy((u_char*)arcsoft+EXTRA_CLIENTDATA,
1380                 (u_char*)hdr+EXTRA_CLIENTDATA,4);
1381         memcpy((u_char*)arcsoft+sizeof(struct ClientData),
1382                 data,length-4);
1383                 
1384         BUGLVL(D_DURING) printk("arcnet: transmitting packet to station %02Xh (%d bytes, type=%d)\n",
1385                         daddr,length,pkttype);
1386                         
1387         BUGLVL(D_TX)
1388         {
1389                 int countx,county;
1390                 
1391                 printk("arcnet: packet dump [tx] follows:");
1392 
1393                 for (county=0; county<16+(pkttype!=NORMAL)*16; county++)
1394                 {
1395                         printk("\n[%04X] ",county*16);
1396                         for (countx=0; countx<16; countx++)
1397                                 printk("%02X ",
1398                                         arcpacket->raw[county*16+countx]);
1399                 }
1400                 
1401                 printk("\n");
1402         }
1403 
1404 #ifdef VERIFY_ACK
1405         lp->outgoing.lastload_dest=hdr->daddr;
1406 #endif
1407         lp->txready=lp->txbuf;  /* packet is ready for sending */
1408 }
1409 
1410 /* Actually start transmitting a packet that was placed in the card's
1411  * buffer by arcnetA_prepare_tx.
1412  */
1413 static void
1414 arcnetA_go_tx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1415 {
1416         struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
1417         int ioaddr=dev->base_addr;
1418 
1419         BUGLVL(D_DURING)
1420                 printk("arcnet: go_tx: status=%Xh\n",
1421                         inb(STATUS));
1422         
1423         if (!(inb(STATUS)&TXFREEflag) || !lp->txready) return;
1424 
1425         /* start sending */
1426         outb(TXcmd|(lp->txready<<3),COMMAND);
1427 
1428         outb(TXFREEflag|NORXflag|RECON_flag,INTMASK);
1429 
1430         dev->trans_start = jiffies;
1431         lp->txready=0;
1432         lp->sending++;
1433 #ifdef VERIFY_ACK       
1434         lp->outgoing.lasttrans_dest=lp->outgoing.lastload_dest;
1435         lp->outgoing.lastload_dest=0;
1436 #endif
1437 }
1438 
1439 
1440 /* Called by the kernel in order to transmit an ethernet-type packet.
1441  */
1442 static int
1443 arcnetE_send_packet(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1444 {
1445         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1446         
1447         BUGLVL(D_DURING)
1448                 printk("%s: in arcnetE_send_packet (skb=%p)\n",dev->name,skb);
1449 
1450         if (IF_TBUSY)
1451         {
1452                 /* If we get here, some higher level has decided we are broken.
1453                    There should really be a "kick me" function call instead. */
1454                 int tickssofar = jiffies - dev->trans_start;
1455                 if (tickssofar < 10)
1456                         return 1;
1457                 printk("%s: transmit timed out\n",dev->name);
1458                 
1459                 /* Try to restart the adaptor. */
1460                 TBUSY=0;
1461                 dev->trans_start = jiffies;
1462                 return 0;
1463         }
1464 
1465         /* If some higher layer thinks we've missed an tx-done interrupt
1466            we are passed NULL. Caution: dev_tint() handles the cli()/sti()
1467            itself. */
1468         if (skb == NULL)
1469         {
1470                 dev_tint(dev);
1471                 return 0;
1472         }
1473 
1474         /* Block a timer-based transmit from overlapping.  This could better be
1475            done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
1476         if (set_bit(0, (void*)&dev->tbusy) != 0)
1477                 printk("%s: Transmitter access conflict.\n", dev->name);
1478         else
1479         {
1480                 union ArcPacket *arcpacket = 
1481                         (union ArcPacket *)(dev->mem_start+512*(lp->txbuf^1));
1482                 u_char *arcsoft,daddr;
1483                 short offset,length=skb->len+1;
1484                 
1485                 TBUSY=1;
1486                 
1487                 if (length>XMTU)
1488                 {
1489                         printk("arcnet: MTU for %s and %s must be <= 493 for ethernet encap.\n",
1490                                 lp->adev->name,lp->edev->name);
1491                         printk("arcnet: transmit aborted.\n");
1492 
1493                         dev_kfree_skb(skb,FREE_WRITE);
1494                         return 0;
1495                 }
1496                 
1497                 BUGLVL(D_DURING)
1498                         printk("arcnet: starting tx sequence...\n");
1499 
1500                 lp->txbuf=lp->txbuf^1; /* XOR with 1 to alternate btw 2 & 3 */
1501 
1502                 /* clean out the page to make debugging make more sense :) */
1503                 BUGLVL(D_DURING)
1504                         memset((void *)dev->mem_start+lp->txbuf*512,0x42,512);
1505 
1506                 /* broadcasts have address FF:FF:FF:FF:FF:FF in etherspeak */
1507                 if (((struct ethhdr*)(skb->data))->h_dest[0] == 0xFF)
1508                         daddr=arcpacket->hardheader.destination=0;
1509                 else
1510                         daddr=arcpacket->hardheader.destination=
1511                                 ((struct ethhdr*)(skb->data))->h_dest[5];
1512 
1513                 /* load packet into shared memory */
1514                 offset=512-length;
1515                 if (length>MTU)         /* long/exception packet */
1516                 {
1517                         if (length<MinTU) offset-=3;
1518                         arcpacket->hardheader.offset1=0;
1519                         arcpacket->hardheader.offset2=offset;
1520                 }
1521                 else                    /* short packet */
1522                 {
1523                         arcpacket->hardheader.offset1=(offset-=256);
1524                 }
1525                 
1526                 BUGLVL(D_DURING)
1527                         printk("arcnet: length=%Xh, offset=%Xh, offset1=%Xh, offset2=%Xh\n",
1528                                 length,offset,arcpacket->hardheader.offset1,
1529                                 arcpacket->hardheader.offset2);
1530                 
1531                 arcsoft=&arcpacket->raw[offset];
1532                 arcsoft[0]=ARC_P_MS_TCPIP;
1533                 arcsoft++;
1534                 
1535                 /* copy the packet into ARCnet shmem
1536                  *  - the first bytes of ClientData header are skipped
1537                  */
1538                 BUGLVL(D_DURING) printk("arcnet: ready to memcpy\n");
1539                 
1540                 memcpy(arcsoft,skb->data,skb->len);
1541                         
1542                 BUGLVL(D_DURING)
1543                         printk("arcnet: transmitting packet to station %02Xh (%d bytes)\n",
1544                                 daddr,length);
1545                                 
1546                 BUGLVL(D_TX)
1547                 {
1548                         int countx,county;
1549                         
1550                         printk("arcnet: packet dump [tx] follows:");
1551 
1552                         for (county=0; county<16+(length>=240)*16; county++)
1553                         {
1554                                 printk("\n[%04X] ",county*16);
1555                                 for (countx=0; countx<16; countx++)
1556                                         printk("%02X ",
1557                                                 arcpacket->raw[county*16+countx]);
1558                         }
1559                         
1560                         printk("\n");
1561                 }
1562 
1563         #ifdef VERIFY_ACK
1564                 lp->outgoing.lastload_dest=daddr;
1565         #endif
1566                 lp->txready=lp->txbuf;  /* packet is ready for sending */
1567 
1568                 arcnetA_go_tx(dev);
1569                 dev->trans_start = jiffies;
1570         }
1571 
1572         dev_kfree_skb(skb,FREE_WRITE);
1573 
1574         return 0;
1575 }
1576 
1577 
1578 /****************************************************************************
1579  *                                                                          *
1580  * Interrupt handler                                                        *
1581  *                                                                          *
1582  ****************************************************************************/
1583 
1584 
1585 /* The typical workload of the driver:  Handle the network interface
1586  * interrupts.  This doesn't do much right now except call arcnet_inthandler,
1587  * which takes different parameters but is sometimes called from other places
1588  * as well.
1589  */
1590 static void
1591 arcnet_interrupt(int irq,struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
1592 {
1593         struct device *dev = (struct device *)(irq2dev_map[irq]);
1594 
1595         if (dev==NULL || !dev->start)
1596         {
1597                 BUGLVL(D_EXTRA)
1598                         printk("arcnet: irq %d for unknown device.\n", irq);
1599                 return;
1600         }
1601 
1602         arcnet_inthandler(dev);
1603 }
1604 
1605 
1606 /* The actual interrupt handler routine - handle various IRQ's generated
1607  * by the card.
1608  */
1609 static void
1610 arcnet_inthandler(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1611 {       
1612         struct arcnet_local *lp;
1613         int ioaddr, status, boguscount = 3, didsomething;
1614         
1615         if (dev->interrupt)
1616                 printk("arcnet: DRIVER PROBLEM!  Nested arcnet interrupts!\n");
1617         
1618         dev->interrupt = 1;
1619 
1620         ioaddr = dev->base_addr;
1621         lp = (struct arcnet_local *)dev->priv;
1622 
1623         outb(0,INTMASK);
1624         sti();
1625         
1626         BUGLVL(D_DURING)
1627                 printk("arcnet: in net_interrupt (status=%Xh)\n",inb(STATUS));
1628 
1629         do
1630         {
1631                 status = inb(STATUS);
1632                 didsomething=0;
1633         
1634                 if (!dev->start)
1635                 {
1636                         BUGLVL(D_DURING)
1637                                 printk("arcnet: ARCnet not yet initialized.  irq ignored. (status=%Xh)\n",
1638                                         status);
1639                         if (!(status&NORXflag))
1640                                 outb(NORXflag|RECON_flag,INTMASK);
1641 
1642                         dev->interrupt=0;
1643                         return;
1644                 }
1645         
1646                 /* RESET flag was enabled - card is resetting and if RX
1647                  * is disabled, it's NOT because we just got a packet.
1648                  */
1649                 if (status & RESETflag)
1650                 {
1651                         outb(CFLAGScmd|RESETclear,COMMAND);
1652                         BUGLVL(D_INIT)
1653                                 printk("arcnet: reset irq (status=%Xh)\n",
1654                                         status);
1655                 }
1656 #ifdef DETECT_RECONFIGS
1657                 if (status & RECONflag)
1658                 {
1659                         outb(CFLAGScmd|CONFIGclear,COMMAND);
1660                         BUGLVL(D_EXTRA)
1661                                 printk("arcnet: Network reconfiguration detected (status=%Xh)\n",
1662                                         status);
1663                         lp->stats.tx_carrier_errors++;
1664                 }
1665 #endif
1666 
1667                 /* RX is inhibited - we must have received something. */
1668                 if (status & NORXflag)
1669                 {
1670                         int recbuf=lp->recbuf=!lp->recbuf;
1671 
1672                         BUGLVL(D_DURING)
1673                                 printk("arcnet: receive irq (status=%Xh)\n",
1674                                         status);
1675 
1676                         /* enable receive of our next packet */
1677                         EnableReceiver();
1678                 
1679                         /* Got a packet. */
1680                         arcnet_rx(dev,!recbuf);
1681                         
1682                         didsomething++;
1683                 }
1684 
1685                 /* it can only be an xmit-done irq if we're xmitting :) */
1686                 if (status&TXFREEflag && !lp->in_txhandler && lp->sending)
1687                 {
1688                         struct Outgoing *out=&(lp->outgoing);
1689                         
1690                         lp->in_txhandler++;
1691                         lp->sending--;
1692                         
1693                         BUGLVL(D_DURING)
1694                                 printk("arcnet: TX IRQ (stat=%Xh, numsegs=%d, segnum=%d, skb=%ph)\n",
1695                                         status,out->numsegs,out->segnum,out->skb);
1696                                         
1697 #ifdef VERIFY_ACK
1698                         if (!(status&TXACKflag))
1699                         {
1700                                 if (lp->outgoing.lasttrans_dest != 0)
1701                                 {
1702                                         BUGLVL(D_NORMAL)
1703                                                 printk("arcnet: transmit was not acknowledged! (status=%Xh, dest=%d)\n",
1704                                                         status,
1705                                                         lp->outgoing.lasttrans_dest);
1706                                         lp->stats.tx_errors++;
1707                                 }
1708                                 else
1709                                 {
1710                                         BUGLVL(D_DURING)
1711                                                 printk("arcnet: broadcast was not acknowledged; that's normal (status=%Xh, dest=%d)\n",
1712                                                         status,
1713                                                         lp->outgoing.lasttrans_dest);
1714                                 }
1715                         }
1716 #endif
1717                                         
1718                         /* send packet if there is one */
1719                         if (lp->txready)
1720                         {
1721                                 arcnetA_go_tx(dev);
1722                                 didsomething++;
1723                         }
1724                         
1725                         if (lp->intx)
1726                         {
1727                                 lp->in_txhandler--;
1728                                 continue;
1729                         }
1730 
1731                         if (!lp->outgoing.skb)
1732                         {
1733                                 BUGLVL(D_DURING)
1734                                         printk("arcnet: TX IRQ done: no split to continue.\n");
1735                                 
1736                                 /* inform upper layers */
1737                                 if (!lp->txready && IF_TBUSY)
1738                                 {
1739                                         TBUSY=0;
1740                                         mark_bh(NET_BH);
1741                                 }
1742                                 
1743                                 lp->in_txhandler--;
1744                                 continue;
1745                         }
1746                         
1747                         /*lp->stats.tx_packets++;*/
1748                         
1749                         /* if more than one segment, and not all segments
1750                          * are done, then continue xmit.
1751                          */
1752                         if (out->segnum<out->numsegs)
1753                                 arcnetA_continue_tx(dev);
1754                         if (lp->txready && !lp->sending)
1755                                 arcnetA_go_tx(dev);
1756 
1757                         /* if segnum==numsegs, the transmission is finished;
1758                          * free the skb.
1759                          */
1760                         if (out->segnum>=out->numsegs)
1761                         {
1762                                 /* transmit completed */
1763                                 out->segnum++;
1764                                 if (out->skb)
1765                                         dev_kfree_skb(out->skb,FREE_WRITE);
1766                                 out->skb=NULL;
1767 
1768                                 /* inform upper layers */
1769                                 if (!lp->txready && IF_TBUSY)
1770                                 {
1771                                         TBUSY=0;
1772                                         mark_bh(NET_BH);
1773                                 }
1774                         }
1775                         didsomething++;
1776                         
1777                         lp->in_txhandler--;
1778                 }
1779 
1780         } while (--boguscount && didsomething);
1781 
1782         BUGLVL(D_DURING)
1783                 printk("arcnet: net_interrupt complete (status=%Xh)\n\n",
1784                         inb(STATUS));
1785 
1786         if (dev->start && lp->sending )
1787                 outb(NORXflag|TXFREEflag|RECON_flag,INTMASK);
1788         else
1789                 outb(NORXflag|RECON_flag,INTMASK);
1790 
1791         dev->interrupt=0;
1792 }
1793 
1794 
1795 /****************************************************************************
1796  *                                                                          *
1797  * Receiver routines                                                        *
1798  *                                                                          *
1799  ****************************************************************************/
1800 
1801 
1802 /* A packet has arrived; grab it from the buffers and possibly unsplit it.
1803  * This is a generic packet receiver that calls arcnet??_rx depending on the
1804  * protocol ID found.
1805  */
1806 static void
1807 arcnet_rx(struct device *dev,int recbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
1808 {
1809         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1810         int ioaddr = dev->base_addr;
1811         union ArcPacket *arcpacket=
1812                 (union ArcPacket *)(dev->mem_start+recbuf*512);
1813         u_char *arcsoft;
1814         short length,offset;
1815         u_char daddr,saddr;
1816 
1817         saddr=arcpacket->hardheader.source;
1818         daddr=arcpacket->hardheader.destination;
1819         
1820         /* if source is 0, it's a "used" packet! */
1821         if (saddr==0)
1822         {
1823                 printk("arcnet: discarding old packet. (status=%Xh)\n",
1824                         inb(STATUS));
1825                 lp->stats.rx_errors++;
1826                 return;
1827         }
1828         arcpacket->hardheader.source=0;
1829         
1830         if (arcpacket->hardheader.offset1) /* Normal Packet */
1831         {
1832                 offset=arcpacket->hardheader.offset1;
1833                 arcsoft=&arcpacket->raw[offset];
1834                 length=256-offset;
1835         }
1836         else            /* ExtendedPacket or ExceptionPacket */
1837         {
1838                 offset=arcpacket->hardheader.offset2;
1839                 arcsoft=&arcpacket->raw[offset];
1840 
1841                 length=512-offset;
1842         }
1843         
1844         BUGLVL(D_DURING)
1845                 printk("arcnet: received packet from %02Xh to %02Xh (%d bytes)\n",
1846                         saddr,daddr,length);
1847 
1848         /* call the right receiver for the protocol */
1849         switch (arcsoft[0])
1850         {
1851         case ARC_P_IP:
1852         case ARC_P_ARP:
1853         case ARC_P_RARP:
1854         case ARC_P_IPX:
1855                 arcnetA_rx(dev,(struct ClientData*)arcsoft,
1856                         length,saddr,daddr);
1857                 break;
1858         case ARC_P_MS_TCPIP:
1859                 arcnetE_rx(dev,arcsoft,length,saddr,daddr);
1860                 break;          
1861         default:
1862                 printk("arcnet: received unknown protocol %d (%Xh)\n",
1863                         arcsoft[0],arcsoft[0]);
1864                 break;
1865         }
1866 
1867         BUGLVL(D_RX)
1868         {
1869                 int countx,county;
1870                 
1871                 printk("arcnet: rx packet dump follows:");
1872 
1873                 for (county=0; county<16+(length>240)*16; county++)
1874                 {
1875                         printk("\n[%04X] ",county*16);
1876                         for (countx=0; countx<16; countx++)
1877                                 printk("%02X ",
1878                                         arcpacket->raw[county*16+countx]);
1879                 }
1880                 
1881                 printk("\n");
1882         }
1883 
1884 
1885         /* clean out the page to make debugging make more sense :) */
1886         BUGLVL(D_DURING)
1887                 memset((void *)arcpacket->raw,0x42,512);
1888 
1889 
1890         /* If any worth-while packets have been received, a mark_bh(NET_BH)
1891          * has been done by netif_rx and Linux will handle them after we
1892          * return.
1893          */
1894 }
1895 
1896 
1897 /* Packet receiver for "standard" RFC1201-style packets
1898  */
1899 static void
1900 arcnetA_rx(struct device *dev,struct ClientData *arcsoft,
     /* [previous][next][first][last][top][bottom][index][help] */
1901         int length,u_char saddr, u_char daddr)
1902 {
1903         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1904         struct sk_buff *skb;
1905         struct ClientData *soft;
1906         
1907         BUGLVL(D_DURING)
1908                 printk("arcnet: it's an RFC1201 packet (length=%d)\n",
1909                         length);
1910                         
1911         arcsoft=(struct ClientData *)((u_char *)arcsoft-EXTRA_CLIENTDATA);
1912         length+=EXTRA_CLIENTDATA;
1913 
1914         if (arcsoft->split_flag==0xFF)  /* Exception Packet */
1915         {
1916                 BUGLVL(D_DURING)
1917                         printk("arcnet: compensating for exception packet\n");
1918 
1919                 /* skip over 4-byte junkola */
1920                 arcsoft=(struct ClientData *)
1921                         ((u_char *)arcsoft + 4);
1922                 length-=4;
1923         }
1924         
1925         if (!arcsoft->split_flag)               /* not split */
1926         {
1927                 struct Incoming *in=&lp->incoming[saddr];
1928 
1929                 BUGLVL(D_RX) printk("arcnet: incoming is not split (splitflag=%d)\n",
1930                         arcsoft->split_flag);
1931                         
1932                 if (in->skb)    /* already assembling one! */
1933                 {
1934                         BUGLVL(D_EXTRA) printk("arcnet: aborting assembly (seq=%d) for unsplit packet (splitflag=%d, seq=%d)\n",
1935                                 in->sequence,arcsoft->split_flag,
1936                                 arcsoft->sequence);
1937                         kfree_skb(in->skb,FREE_WRITE);
1938                         lp->stats.tx_dropped++;
1939                         lp->stats.rx_errors++;
1940                         in->skb=NULL;
1941                 }
1942                 
1943                 in->sequence=arcsoft->sequence;
1944 
1945                 skb = alloc_skb(length, GFP_ATOMIC);
1946                 if (skb == NULL) {
1947                         printk("arcnet: Memory squeeze, dropping packet.\n");
1948                         lp->stats.rx_dropped++;
1949                         return;
1950                 }
1951                 soft=(struct ClientData *)skb->data;
1952                 
1953                 skb->len = length;
1954                 skb->dev = dev;
1955                 
1956                 memcpy((u_char *)soft+EXTRA_CLIENTDATA,
1957                         (u_char *)arcsoft+EXTRA_CLIENTDATA,
1958                         length-EXTRA_CLIENTDATA);
1959                 soft->daddr=daddr;
1960                 soft->saddr=saddr;
1961                 
1962                 /* ARP packets have problems when sent from DOS.
1963                  * source address is always 0 on some systems!  So we take
1964                  * the hardware source addr (which is impossible to fumble)
1965                  * and insert it ourselves.
1966                  */
1967                 if (soft->protocol_id == ARC_P_ARP)
1968                 {
1969                         struct arphdr *arp=(struct arphdr *)
1970                                         ((char *)soft+sizeof(struct ClientData));
1971 
1972                         /* make sure addresses are the right length */
1973                         if (arp->ar_hln==1 && arp->ar_pln==4)
1974                         {
1975                                 char *cptr=(char *)(arp)+sizeof(struct arphdr);
1976                                 
1977                                 if (!*cptr)     /* is saddr = 00? */
1978                                 {
1979                                         BUGLVL(D_EXTRA)
1980                                                 printk("arcnet: ARP source address was 00h, set to %02Xh.\n",
1981                                                         saddr);
1982                                         *cptr=saddr;
1983                                 }
1984                                 else BUGLVL(D_DURING) 
1985                                 {
1986                                         printk("arcnet: ARP source address (%Xh) is fine.\n",
1987                                                 *cptr);
1988                                 }
1989                         }
1990                         else
1991                         {
1992                                 printk("arcnet: funny-shaped ARP packet. (%Xh, %Xh)\n",
1993                                         arp->ar_hln,arp->ar_pln);
1994                                 lp->stats.rx_frame_errors++;
1995                         }
1996                 }
1997                 
1998                 BUGLVL(D_SKB)
1999                 {
2000                     short i;
2001                         for( i=0; i< skb->len; i++)
2002                         {
2003                                 if( i%16 == 0 ) printk("\n[%04hX] ",i);
2004                                 printk("%02hX ",((unsigned char*)skb->data)[i]);
2005                         }
2006                         printk("\n");
2007                 }
2008 
2009                         #ifndef LINUX12
2010                         skb->protocol=arcnetA_type_trans(skb,dev);
2011                         #endif
2012 
2013                 netif_rx(skb);
2014                 lp->stats.rx_packets++;
2015          }
2016          else                   /* split packet */
2017          {
2018                  /* NOTE:  MSDOS ARP packet correction should only need to
2019                   * apply to unsplit packets, since ARP packets are so short.
2020                   *
2021                   * My interpretation of the RFC1201 (ARCnet) document is that
2022                   * if a packet is received out of order, the entire assembly
2023                   * process should be aborted.
2024                   *
2025                   * The RFC also mentions "it is possible for successfully
2026                   * received packets to be retransmitted."  As of 0.40 all
2027                   * previously received packets are allowed, not just the
2028                   * most recent one.
2029                   *
2030                   * We allow multiple assembly processes, one for each
2031                   * ARCnet card possible on the network.  Seems rather like
2032                   * a waste of memory.  Necessary?
2033                   */
2034                   
2035                 struct Incoming *in=&lp->incoming[saddr];
2036                 
2037                 BUGLVL(D_RX) printk("arcnet: packet is split (splitflag=%d, seq=%d)\n",
2038                         arcsoft->split_flag,in->sequence);
2039 
2040                 if (in->skb && in->sequence!=arcsoft->sequence)
2041                 {
2042                         BUGLVL(D_EXTRA) printk("arcnet: wrong seq number, aborting assembly (expected=%d, seq=%d, splitflag=%d)\n",     
2043                                 in->sequence,arcsoft->sequence,
2044                                 arcsoft->split_flag);
2045                         kfree_skb(in->skb,FREE_WRITE);
2046                         in->skb=NULL;
2047                         lp->stats.tx_dropped++;
2048                         lp->stats.rx_fifo_errors++;
2049                         in->lastpacket=in->numpackets=0;
2050                 }
2051                   
2052                 if (arcsoft->split_flag & 1)    /* first packet in split */
2053                 {
2054                         BUGLVL(D_RX) printk("arcnet: brand new splitpacket (splitflag=%d)\n",
2055                                 arcsoft->split_flag);
2056                         if (in->skb)    /* already assembling one! */
2057                         {
2058                                 BUGLVL(D_EXTRA) printk("arcnet: aborting previous (seq=%d) assembly (splitflag=%d, seq=%d)\n",
2059                                         in->sequence,arcsoft->split_flag,
2060                                         arcsoft->sequence);
2061                                 lp->stats.tx_dropped++;
2062                                 lp->stats.rx_over_errors++;
2063                                 kfree_skb(in->skb,FREE_WRITE);
2064                         }
2065 
2066                         in->sequence=arcsoft->sequence;
2067                         in->numpackets=((unsigned)arcsoft->split_flag>>1)+2;
2068                         in->lastpacket=1;
2069                         
2070                         if (in->numpackets>16)
2071                         {
2072                                 BUGLVL(D_EXTRA) printk("arcnet: incoming packet more than 16 segments; dropping. (splitflag=%d)\n",
2073                                         arcsoft->split_flag);
2074                                 lp->stats.rx_dropped++;
2075                                 return;
2076                         }
2077                 
2078                         in->skb=skb=alloc_skb(508*in->numpackets
2079                                         + sizeof(struct ClientData),
2080                                         GFP_ATOMIC);
2081                         if (skb == NULL) {
2082                                 printk("%s: (split) memory squeeze, dropping packet.\n", 
2083                                         dev->name);
2084                                 lp->stats.rx_dropped++;
2085                                 return;
2086                         }
2087                                         
2088                         /* I don't know what this is for, but it DOES avoid
2089                          * warnings...
2090                          */
2091                         skb->free=1;
2092                         
2093                         soft=(struct ClientData *)skb->data;
2094                         
2095                         skb->len=sizeof(struct ClientData);
2096                         skb->dev=dev;
2097 
2098                         memcpy((u_char *)soft+EXTRA_CLIENTDATA,
2099                                 (u_char *)arcsoft+EXTRA_CLIENTDATA,
2100                                 sizeof(struct ClientData)-EXTRA_CLIENTDATA);
2101                         soft->split_flag=0; /* final packet won't be split */
2102                 }
2103                 else                    /* not first packet */
2104                 {
2105                         int packetnum=((unsigned)arcsoft->split_flag>>1) + 1;
2106 
2107                         /* if we're not assembling, there's no point
2108                          * trying to continue.
2109                          */                     
2110                         if (!in->skb)
2111                         {
2112                                 BUGLVL(D_EXTRA) printk("arcnet: can't continue split without starting first! (splitflag=%d, seq=%d)\n",
2113                                         arcsoft->split_flag,arcsoft->sequence);
2114                                 lp->stats.rx_errors++;
2115                                 return;
2116                         }
2117 
2118                         in->lastpacket++;
2119                         if (packetnum!=in->lastpacket) /* not the right flag! */
2120                         {
2121                                 /* harmless duplicate? ignore. */
2122                                 if (packetnum<=in->lastpacket-1)
2123                                 {
2124                                         BUGLVL(D_EXTRA) printk("arcnet: duplicate splitpacket ignored! (splitflag=%d)\n",
2125                                                 arcsoft->split_flag);
2126                                         return;
2127                                 }
2128                                 
2129                                 /* "bad" duplicate, kill reassembly */
2130                                 BUGLVL(D_EXTRA) printk("arcnet: out-of-order splitpacket, reassembly (seq=%d) aborted (splitflag=%d, seq=%d)\n",        
2131                                         in->sequence,arcsoft->split_flag,
2132                                         arcsoft->sequence);
2133                                 kfree_skb(in->skb,FREE_WRITE);
2134                                 in->skb=NULL;
2135                                 lp->stats.tx_dropped++;
2136                                 lp->stats.rx_fifo_errors++;
2137                                 in->lastpacket=in->numpackets=0;
2138                                 return;
2139                         }
2140 
2141                         soft=(struct ClientData *)in->skb->data;
2142                 }
2143                 
2144                 skb=in->skb;
2145                 
2146                 memcpy(skb->data+skb->len,
2147                        (u_char *)arcsoft+sizeof(struct ClientData),
2148                        length-sizeof(struct ClientData));
2149 
2150                 skb->len+=length-sizeof(struct ClientData);
2151                 
2152                 soft->daddr=daddr;
2153                 soft->saddr=saddr;
2154                 
2155                 /* are we done? */
2156                 if (in->lastpacket == in->numpackets)
2157                 {
2158                         if (!skb || !in->skb)
2159                                 printk("arcnet: ?!? done reassembling packet, no skb? (skb=%ph, in->skb=%ph)\n",
2160                                         skb,in->skb);
2161                         in->skb=NULL;
2162                         in->lastpacket=in->numpackets=0;
2163                         
2164                         BUGLVL(D_SKB)
2165                         {
2166                             short i;
2167                                 for( i=0; i< skb->len; i++)
2168                                 {
2169                                         if( i%16 == 0 ) printk("\n[%04hX] ",i);
2170                                         printk("%02hX ",((unsigned char*)skb->data)[i]);
2171                                 }
2172                                 printk("\n");
2173                         }
2174 
2175                         
2176                                 #ifndef LINUX12
2177                                 skb->protocol=arcnetA_type_trans(skb,dev);
2178                                 #endif
2179                                 
2180                         netif_rx(skb);
2181                         lp->stats.rx_packets++;
2182                 }
2183          }
2184 }
2185 
2186 
2187 /* Packet receiver for non-standard ethernet-style packets
2188  */
2189 static void
2190 arcnetE_rx(struct device *dev,u_char *arcsoft,
     /* [previous][next][first][last][top][bottom][index][help] */
2191         int length,u_char saddr, u_char daddr)
2192 {
2193         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2194         struct sk_buff *skb;
2195         
2196         BUGLVL(D_DURING)
2197                 printk("arcnet: it's an ethernet-encap packet (length=%d)\n",
2198                         length);
2199 
2200         skb = alloc_skb(length, GFP_ATOMIC);
2201         if (skb == NULL) {
2202                 printk("arcnet: Memory squeeze, dropping packet.\n");
2203                 lp->stats.rx_dropped++;
2204                 return;
2205         }
2206         
2207         skb->len = length;
2208         skb->dev = lp->edev;
2209         
2210         memcpy(skb->data,(u_char *)arcsoft+1,length-1);
2211 
2212         BUGLVL(D_SKB)
2213         {
2214                 short i;
2215                 printk("arcnet: rx skb dump follows:\n");
2216                 for(i=0; i<skb->len; i++)
2217                 {
2218                         if (i%16==0)
2219                                 printk("\n[%04hX] ",i);
2220                         else
2221                                 printk("%02hX ",((u_char *)skb->data)[i]);
2222                 }
2223                 printk("\n");
2224         }
2225         
2226                 #ifndef LINUX12
2227                 skb->protocol=eth_type_trans(skb,dev);
2228                 #endif
2229         
2230         netif_rx(skb);
2231         lp->stats.rx_packets++;
2232 }
2233 
2234 
2235 /****************************************************************************
2236  *                                                                          *
2237  * Miscellaneous routines                                                   *
2238  *                                                                          *
2239  ****************************************************************************/
2240 
2241 
2242 /* Get the current statistics.  This may be called with the card open or
2243  * closed.
2244  */
2245 
2246 static struct enet_statistics *
2247 arcnet_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
2248 {
2249         struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2250 
2251         return &lp->stats;
2252 }
2253 
2254 /* Set or clear the multicast filter for this adaptor.
2255  * num_addrs == -1      Promiscuous mode, receive all packets
2256  * num_addrs == 0       Normal mode, clear multicast list
2257  * num_addrs > 0        Multicast mode, receive normal and MC packets, and do
2258  *                      best-effort filtering.
2259  */
2260 static void
2261 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
2262 {
2263 #if 0     /* no promiscuous mode at all on most ARCnet models */
2264         struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
2265 
2266         short ioaddr = dev->base_addr;
2267         if (num_addrs) {
2268                 outw(69, ioaddr);               /* Enable promiscuous mode */
2269         } else
2270                 outw(99, ioaddr);               /* Disable promiscuous mode, use normal mode */
2271 #endif
2272 }
2273 
2274 /* Create the ARCnet ClientData header for an arbitrary protocol layer
2275  *
2276  * saddr=NULL   means use device source address (always will anyway)
2277  * daddr=NULL   means leave destination address (eg unresolved arp)
2278  */
2279 #ifdef LINUX12
2280 int arcnetA_header(unsigned char *buff,struct device *dev,
     /* [previous][next][first][last][top][bottom][index][help] */
2281                 unsigned short type,void *daddr,void *saddr,unsigned len,
2282                 struct sk_buff *skb)
2283 #else
2284 int arcnetA_header(struct sk_buff *skb,struct device *dev,
2285                 unsigned short type,void *daddr,void *saddr,unsigned len)
2286 #endif
2287 {
2288         struct ClientData *head = (struct ClientData *)
2289 #ifdef LINUX12
2290                 buff;
2291 #else
2292                 skb_push(skb,dev->hard_header_len);
2293 #endif
2294 /*      struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);*/
2295 
2296         /* set the protocol ID according to RFC-1201 */
2297         switch(type)
2298         {
2299         case ETH_P_IP:
2300                 head->protocol_id=ARC_P_IP;
2301                 break;
2302         case ETH_P_ARP:
2303                 head->protocol_id=ARC_P_ARP;
2304                 break;
2305         case ETH_P_RARP:
2306                 head->protocol_id=ARC_P_RARP;
2307                 break;
2308         case ETH_P_IPX:
2309                 head->protocol_id=ARC_P_IPX;
2310                 break;
2311         case ETH_P_ATALK:
2312                 head->protocol_id=ARC_P_ATALK;
2313                 break;
2314         default:
2315                 printk("arcnet: I don't understand protocol %d (%Xh)\n",
2316                         type,type);
2317                 return 0;
2318         }       
2319 
2320         /*
2321          * Set the source hardware address.
2322          *
2323          * This is pretty pointless for most purposes, but it can help
2324          * in debugging.  saddr is stored in the ClientData header and
2325          * removed before sending the packet (since ARCnet does not allow
2326          * us to change the source address in the actual packet sent)
2327          */
2328         if(saddr)
2329                 head->saddr=((u_char*)saddr)[0];
2330         else
2331                 head->saddr=((u_char*)(dev->dev_addr))[0];
2332 
2333 #if 0
2334         /*
2335          *      Anyway, the loopback-device should never use this function... 
2336          *
2337          *      And the chances of it using the ARCnet version of it are so
2338          *      tiny that I don't think we have to worry :)
2339          */
2340         if (dev->flags & IFF_LOOPBACK) 
2341         {
2342                 head->daddr=0;
2343                 return(dev->hard_header_len);
2344         }
2345 #endif
2346 
2347         head->split_flag=0;     /* split packets are done elsewhere */
2348         head->sequence=0;       /* so are sequence numbers */
2349 
2350         /* supposedly if daddr is NULL, we should ignore it... */
2351         if(daddr)
2352         {
2353                 head->daddr=((u_char*)daddr)[0];
2354                 return dev->hard_header_len;
2355         }
2356         else
2357                 head->daddr=0;  /* better fill one in anyway */
2358                 
2359         return -dev->hard_header_len;
2360 }
2361 
2362 
2363 /* Rebuild the ARCnet ClientData header. This is called after an ARP
2364  * (or in future other address resolution) has completed on this
2365  * sk_buff. We now let ARP fill in the other fields.
2366  */
2367 int arcnetA_rebuild_header(void *buff,struct device *dev,unsigned long dst,
     /* [previous][next][first][last][top][bottom][index][help] */
2368                 struct sk_buff *skb)
2369 {
2370         struct ClientData *head = (struct ClientData *)buff;
2371 
2372         /*
2373          * Only ARP and IP are currently supported
2374          */
2375          
2376         if(head->protocol_id != ARC_P_IP) 
2377         {
2378                 printk("arcnet: I don't understand resolve type %d (%Xh) addresses!\n",
2379                         head->protocol_id,head->protocol_id);
2380                 head->daddr=0;
2381                 /*memcpy(eth->h_source, dev->dev_addr, dev->addr_len);*/
2382                 return 0;
2383         }
2384 
2385         /*
2386          * Try and get ARP to resolve the header.
2387          */
2388 #ifdef CONFIG_INET       
2389         return arp_find(&(head->daddr), dst, dev, dev->pa_addr, skb)? 1 : 0;
2390 #else
2391         return 0;       
2392 #endif  
2393 }
2394                 
2395 /* Determine a packet's protocol ID.
2396  *
2397  * With ARCnet we have to convert everything to Ethernet-style stuff.
2398  */
2399 unsigned short arcnetA_type_trans(struct sk_buff *skb,struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
2400 {
2401         struct ClientData *head = (struct ClientData *) skb->data;
2402         struct arcnet_local *lp=(struct arcnet_local *) (dev->priv);
2403 
2404 #ifndef LINUX12
2405         /* Pull off the arcnet header. */
2406         skb->mac.raw=skb->data;
2407         skb_pull(skb,dev->hard_header_len);
2408 #endif
2409         
2410         if (head->daddr==0)
2411                 skb->pkt_type=PACKET_BROADCAST;
2412         else if (dev->flags&IFF_PROMISC)
2413         {
2414                 /* if we're not sending to ourselves :) */
2415                 if (head->daddr != dev->dev_addr[0])
2416                         skb->pkt_type=PACKET_OTHERHOST;
2417         }
2418         
2419         /* now return the protocol number */
2420         switch (head->protocol_id)
2421         {
2422         case ARC_P_IP:          return htons(ETH_P_IP);
2423         case ARC_P_ARP:         return htons(ETH_P_ARP);
2424         case ARC_P_RARP:        return htons(ETH_P_RARP);
2425         case ARC_P_IPX:         return htons(ETH_P_IPX);
2426         case ARC_P_ATALK:   return htons(ETH_P_ATALK); /* untested appletalk */
2427         case ARC_P_LANSOFT: /* don't understand.  fall through. */
2428         default:
2429                 BUGLVL(D_EXTRA)
2430                         printk("arcnet: received packet of unknown protocol id %d (%Xh)\n",
2431                                 head->protocol_id,head->protocol_id);
2432                 lp->stats.rx_frame_errors++;
2433                 return 0;
2434         }
2435 
2436         return htons(ETH_P_IP);
2437 }
2438 
2439 
2440 
2441 /****************************************************************************
2442  *                                                                          *
2443  * Kernel Loadable Module Support                                           *
2444  *                                                                          *
2445  ****************************************************************************/
2446 
2447 
2448 #ifdef MODULE
2449 char kernel_version[] = UTS_RELEASE;
2450 static struct device thiscard = {
2451   "       ",/* if blank, device name inserted by /linux/drivers/net/net_init.c */
2452   0, 0, 0, 0,
2453   0, 0,  /* I/O address, IRQ */
2454   0, 0, 0, NULL, arcnet_probe };
2455         
2456         
2457 int io=0x0;     /* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */
2458 int irqnum=0;   /* or use the insmod io= irqnum= shmem= options */
2459 int shmem=0;
2460 int num=0;      /* number of device (ie for 0 for arc0, 1 for arc1...) */
2461 
2462 int
2463 init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
2464 {
2465         if (io == 0)
2466           printk("arcnet: You should not use auto-probing with insmod!\n");
2467 
2468         sprintf(thiscard.name,"arc%d",num);
2469 
2470         thiscard.base_addr=io;
2471 
2472         thiscard.irq=irqnum;
2473         if (thiscard.irq==2) thiscard.irq=9;
2474 
2475         if (shmem)
2476         {
2477                 thiscard.mem_start=shmem;
2478                 thiscard.mem_end=thiscard.mem_start+512*4-1;
2479                 thiscard.rmem_start=thiscard.mem_start+512*0;
2480                 thiscard.rmem_end=thiscard.mem_start+512*2-1;
2481         }
2482 
2483         if (register_netdev(&thiscard) != 0)
2484                 return -EIO;
2485         return 0;
2486 }
2487 
2488 void
2489 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
2490 {
2491         if (MOD_IN_USE)
2492         {
2493                 printk("%s: device busy, remove delayed\n",thiscard.name);
2494         }
2495         else
2496         {
2497                 if (thiscard.start) arcnet_close(&thiscard);
2498                 if (thiscard.irq) free_irq(thiscard.irq);
2499                 if (thiscard.base_addr) release_region(thiscard.base_addr,
2500                                                 ARCNET_TOTAL_SIZE);
2501                 unregister_netdev(&thiscard);
2502         }
2503 }
2504 
2505 #endif /* MODULE */
2506 
2507 
2508 
2509 /*
2510  * Local variables:
2511  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c arcnet.c"
2512  *  version-control: t
2513  *  kept-new-versions: 5
2514  *  tab-width: 8
2515  * End:
2516  */
2517 

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