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

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