/*1* INET An implementation of the TCP/IP protocol suite for the LINUX2* operating system. NET is implemented using the BSD Socket3* interface as the means of communication with the user level.4*5* Definitions used by the ARCnet driver.6*7* Authors: Avery Pennarun and David Woodhouse8*9* This program is free software; you can redistribute it and/or10* modify it under the terms of the GNU General Public License11* as published by the Free Software Foundation; either version12* 2 of the License, or (at your option) any later version.13*14*/15#ifndef _LINUX_ARCDEVICE_H16#define _LINUX_ARCDEVICE_H1718#include <asm/timex.h>19#include <linux/if_arcnet.h>2021#ifdef __KERNEL__2223#ifndef bool24#define bool int25#endif2627/*28* RECON_THRESHOLD is the maximum number of RECON messages to receive29* within one minute before printing a "cabling problem" warning. The30* default value should be fine.31*32* After that, a "cabling restored" message will be printed on the next IRQ33* if no RECON messages have been received for 10 seconds.34*35* Do not define RECON_THRESHOLD at all if you want to disable this feature.36*/37#define RECON_THRESHOLD 30383940/*41* Define this to the minimum "timeout" value. If a transmit takes longer42* than TX_TIMEOUT jiffies, Linux will abort the TX and retry. On a large43* network, or one with heavy network traffic, this timeout may need to be44* increased. The larger it is, though, the longer it will be between45* necessary transmits - don't set this too high.46*/47#define TX_TIMEOUT (HZ * 200 / 1000)484950/* Display warnings about the driver being an ALPHA version. */51#undef ALPHA_WARNING525354/*55* Debugging bitflags: each option can be enabled individually.56*57* Note: only debug flags included in the ARCNET_DEBUG_MAX define will58* actually be available. GCC will (at least, GCC 2.7.0 will) notice59* lines using a BUGLVL not in ARCNET_DEBUG_MAX and automatically optimize60* them out.61*/62#define D_NORMAL 1 /* important operational info */63#define D_EXTRA 2 /* useful, but non-vital information */64#define D_INIT 4 /* show init/probe messages */65#define D_INIT_REASONS 8 /* show reasons for discarding probes */66#define D_RECON 32 /* print a message whenever token is lost */67#define D_PROTO 64 /* debug auto-protocol support */68/* debug levels below give LOTS of output during normal operation! */69#define D_DURING 128 /* trace operations (including irq's) */70#define D_TX 256 /* show tx packets */71#define D_RX 512 /* show rx packets */72#define D_SKB 1024 /* show skb's */73#define D_SKB_SIZE 2048 /* show skb sizes */74#define D_TIMING 4096 /* show time needed to copy buffers to card */75#define D_DEBUG 8192 /* Very detailed debug line for line */7677#ifndef ARCNET_DEBUG_MAX78#define ARCNET_DEBUG_MAX (127) /* change to ~0 if you want detailed debugging */79#endif8081#ifndef ARCNET_DEBUG82#define ARCNET_DEBUG (D_NORMAL|D_EXTRA)83#endif84extern int arcnet_debug;8586/* macros to simplify debug checking */87#define BUGLVL(x) if ((ARCNET_DEBUG_MAX)&arcnet_debug&(x))88#define BUGMSG2(x,msg,args...) do { BUGLVL(x) printk(msg, ## args); } while (0)89#define BUGMSG(x,msg,args...) \90BUGMSG2(x, "%s%6s: " msg, \91x==D_NORMAL ? KERN_WARNING \92: x < D_DURING ? KERN_INFO : KERN_DEBUG, \93dev->name , ## args)9495/* see how long a function call takes to run, expressed in CPU cycles */96#define TIME(name, bytes, call) BUGLVL(D_TIMING) { \97unsigned long _x, _y; \98_x = get_cycles(); \99call; \100_y = get_cycles(); \101BUGMSG(D_TIMING, \102"%s: %d bytes in %lu cycles == " \103"%lu Kbytes/100Mcycle\n",\104name, bytes, _y - _x, \105100000000 / 1024 * bytes / (_y - _x + 1));\106} \107else { \108call;\109}110111112/*113* Time needed to reset the card - in ms (milliseconds). This works on my114* SMC PC100. I can't find a reference that tells me just how long I115* should wait.116*/117#define RESETtime (300)118119/*120* These are the max/min lengths of packet payload, not including the121* arc_hardware header, but definitely including the soft header.122*123* Note: packet sizes 254, 255, 256 are impossible because of the way124* ARCnet registers work That's why RFC1201 defines "exception" packets.125* In non-RFC1201 protocols, we have to just tack some extra bytes on the126* end.127*/128#define MTU 253 /* normal packet max size */129#define MinTU 257 /* extended packet min size */130#define XMTU 508 /* extended packet max size */131132/* status/interrupt mask bit fields */133#define TXFREEflag 0x01 /* transmitter available */134#define TXACKflag 0x02 /* transmitted msg. ackd */135#define RECONflag 0x04 /* network reconfigured */136#define TESTflag 0x08 /* test flag */137#define EXCNAKflag 0x08 /* excesive nak flag */138#define RESETflag 0x10 /* power-on-reset */139#define RES1flag 0x20 /* reserved - usually set by jumper */140#define RES2flag 0x40 /* reserved - usually set by jumper */141#define NORXflag 0x80 /* receiver inhibited */142143/* Flags used for IO-mapped memory operations */144#define AUTOINCflag 0x40 /* Increase location with each access */145#define IOMAPflag 0x02 /* (for 90xx) Use IO mapped memory, not mmap */146#define ENABLE16flag 0x80 /* (for 90xx) Enable 16-bit mode */147148/* in the command register, the following bits have these meanings:149* 0-2 command150* 3-4 page number (for enable rcv/xmt command)151* 7 receive broadcasts152*/153#define NOTXcmd 0x01 /* disable transmitter */154#define NORXcmd 0x02 /* disable receiver */155#define TXcmd 0x03 /* enable transmitter */156#define RXcmd 0x04 /* enable receiver */157#define CONFIGcmd 0x05 /* define configuration */158#define CFLAGScmd 0x06 /* clear flags */159#define TESTcmd 0x07 /* load test flags */160161/* flags for "clear flags" command */162#define RESETclear 0x08 /* power-on-reset */163#define CONFIGclear 0x10 /* system reconfigured */164165#define EXCNAKclear 0x0E /* Clear and acknowledge the excive nak bit */166167/* flags for "load test flags" command */168#define TESTload 0x08 /* test flag (diagnostic) */169170/* byte deposited into first address of buffers on reset */171#define TESTvalue 0321 /* that's octal for 0xD1 :) */172173/* for "enable receiver" command */174#define RXbcasts 0x80 /* receive broadcasts */175176/* flags for "define configuration" command */177#define NORMALconf 0x00 /* 1-249 byte packets */178#define EXTconf 0x08 /* 250-504 byte packets */179180/* card feature flags, set during auto-detection.181* (currently only used by com20020pci)182*/183#define ARC_IS_5MBIT 1 /* card default speed is 5MBit */184#define ARC_CAN_10MBIT 2 /* card uses COM20022, supporting 10MBit,185but default is 2.5MBit. */186187188/* information needed to define an encapsulation driver */189struct ArcProto {190char suffix; /* a for RFC1201, e for ether-encap, etc. */191int mtu; /* largest possible packet */192int is_ip; /* This is a ip plugin - not a raw thing */193194void (*rx) (struct net_device * dev, int bufnum,195struct archdr * pkthdr, int length);196int (*build_header) (struct sk_buff * skb, struct net_device *dev,197unsigned short ethproto, uint8_t daddr);198199/* these functions return '1' if the skb can now be freed */200int (*prepare_tx) (struct net_device * dev, struct archdr * pkt, int length,201int bufnum);202int (*continue_tx) (struct net_device * dev, int bufnum);203int (*ack_tx) (struct net_device * dev, int acked);204};205206extern struct ArcProto *arc_proto_map[256], *arc_proto_default,207*arc_bcast_proto, *arc_raw_proto;208209210/*211* "Incoming" is information needed for each address that could be sending212* to us. Mostly for partially-received split packets.213*/214struct Incoming {215struct sk_buff *skb; /* packet data buffer */216__be16 sequence; /* sequence number of assembly */217uint8_t lastpacket, /* number of last packet (from 1) */218numpackets; /* number of packets in split */219};220221222/* only needed for RFC1201 */223struct Outgoing {224struct ArcProto *proto; /* protocol driver that owns this:225* if NULL, no packet is pending.226*/227struct sk_buff *skb; /* buffer from upper levels */228struct archdr *pkt; /* a pointer into the skb */229uint16_t length, /* bytes total */230dataleft, /* bytes left */231segnum, /* segment being sent */232numsegs; /* number of segments */233};234235236struct arcnet_local {237uint8_t config, /* current value of CONFIG register */238timeout, /* Extended timeout for COM20020 */239backplane, /* Backplane flag for COM20020 */240clockp, /* COM20020 clock divider */241clockm, /* COM20020 clock multiplier flag */242setup, /* Contents of setup1 register */243setup2, /* Contents of setup2 register */244intmask; /* current value of INTMASK register */245uint8_t default_proto[256]; /* default encap to use for each host */246int cur_tx, /* buffer used by current transmit, or -1 */247next_tx, /* buffer where a packet is ready to send */248cur_rx; /* current receive buffer */249int lastload_dest, /* can last loaded packet be acked? */250lasttrans_dest; /* can last TX'd packet be acked? */251int timed_out; /* need to process TX timeout and drop packet */252unsigned long last_timeout; /* time of last reported timeout */253char *card_name; /* card ident string */254int card_flags; /* special card features */255256257/* On preemtive and SMB a lock is needed */258spinlock_t lock;259260/*261* Buffer management: an ARCnet card has 4 x 512-byte buffers, each of262* which can be used for either sending or receiving. The new dynamic263* buffer management routines use a simple circular queue of available264* buffers, and take them as they're needed. This way, we simplify265* situations in which we (for example) want to pre-load a transmit266* buffer, or start receiving while we copy a received packet to267* memory.268*269* The rules: only the interrupt handler is allowed to _add_ buffers to270* the queue; thus, this doesn't require a lock. Both the interrupt271* handler and the transmit function will want to _remove_ buffers, so272* we need to handle the situation where they try to do it at the same273* time.274*275* If next_buf == first_free_buf, the queue is empty. Since there are276* only four possible buffers, the queue should never be full.277*/278atomic_t buf_lock;279int buf_queue[5];280int next_buf, first_free_buf;281282/* network "reconfiguration" handling */283unsigned long first_recon; /* time of "first" RECON message to count */284unsigned long last_recon; /* time of most recent RECON */285int num_recons; /* number of RECONs between first and last. */286bool network_down; /* do we think the network is down? */287288bool excnak_pending; /* We just got an excesive nak interrupt */289290struct {291uint16_t sequence; /* sequence number (incs with each packet) */292__be16 aborted_seq;293294struct Incoming incoming[256]; /* one from each address */295} rfc1201;296297/* really only used by rfc1201, but we'll pretend it's not */298struct Outgoing outgoing; /* packet currently being sent */299300/* hardware-specific functions */301struct {302struct module *owner;303void (*command) (struct net_device * dev, int cmd);304int (*status) (struct net_device * dev);305void (*intmask) (struct net_device * dev, int mask);306bool (*reset) (struct net_device * dev, bool really_reset);307void (*open) (struct net_device * dev);308void (*close) (struct net_device * dev);309310void (*copy_to_card) (struct net_device * dev, int bufnum, int offset,311void *buf, int count);312void (*copy_from_card) (struct net_device * dev, int bufnum, int offset,313void *buf, int count);314} hw;315316void __iomem *mem_start; /* pointer to ioremap'ed MMIO */317};318319320#define ARCRESET(x) (lp->hw.reset(dev, (x)))321#define ACOMMAND(x) (lp->hw.command(dev, (x)))322#define ASTATUS() (lp->hw.status(dev))323#define AINTMASK(x) (lp->hw.intmask(dev, (x)))324325326327#if ARCNET_DEBUG_MAX & D_SKB328void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc);329#else330#define arcnet_dump_skb(dev,skb,desc) ;331#endif332333void arcnet_unregister_proto(struct ArcProto *proto);334irqreturn_t arcnet_interrupt(int irq, void *dev_id);335struct net_device *alloc_arcdev(const char *name);336337int arcnet_open(struct net_device *dev);338int arcnet_close(struct net_device *dev);339netdev_tx_t arcnet_send_packet(struct sk_buff *skb,340struct net_device *dev);341void arcnet_timeout(struct net_device *dev);342343#endif /* __KERNEL__ */344#endif /* _LINUX_ARCDEVICE_H */345346347