| 1 | |
| 2 | * INET An implementation of the TCP/IP protocol suite for the LINUX
|
| 3 | * operating system. NET is implemented using the BSD Socket
|
| 4 | * interface as the means of communication with the user level.
|
| 5 | *
|
| 6 | * Definitions used by the ARCnet driver.
|
| 7 | *
|
| 8 | * Authors: Avery Pennarun and David Woodhouse
|
| 9 | *
|
| 10 | * This program is free software; you can redistribute it and/or
|
| 11 | * modify it under the terms of the GNU General Public License
|
| 12 | * as published by the Free Software Foundation; either version
|
| 13 | * 2 of the License, or (at your option) any later version.
|
| 14 | *
|
| 15 |
|
| 16 | #ifndef _LINUX_ARCDEVICE_H
|
| 17 | #define _LINUX_ARCDEVICE_H
|
| 18 |
|
| 19 | #include <asm/timex.h>
|
| 20 | #include <linux/if_arcnet.h>
|
| 21 |
|
| 22 | #ifdef __KERNEL__
|
| 23 | #include <linux/irqreturn.h>
|
| 24 |
|
| 25 | #ifndef bool
|
| 26 | #define bool int
|
| 27 | #endif
|
| 28 |
|
| 29 | |
| 30 | * RECON_THRESHOLD is the maximum number of RECON messages to receive
|
| 31 | * within one minute before printing a "cabling problem" warning. The
|
| 32 | * default value should be fine.
|
| 33 | *
|
| 34 | * After that, a "cabling restored" message will be printed on the next IRQ
|
| 35 | * if no RECON messages have been received for 10 seconds.
|
| 36 | *
|
| 37 | * Do not define RECON_THRESHOLD at all if you want to disable this feature.
|
| 38 |
|
| 39 | #define RECON_THRESHOLD 30
|
| 40 |
|
| 41 |
|
| 42 | |
| 43 | * Define this to the minimum "timeout" value. If a transmit takes longer
|
| 44 | * than TX_TIMEOUT jiffies, Linux will abort the TX and retry. On a large
|
| 45 | * network, or one with heavy network traffic, this timeout may need to be
|
| 46 | * increased. The larger it is, though, the longer it will be between
|
| 47 | * necessary transmits - don't set this too high.
|
| 48 |
|
| 49 | #define TX_TIMEOUT (HZ * 200 / 1000)
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 | #undef ALPHA_WARNING
|
| 54 |
|
| 55 |
|
| 56 | |
| 57 | * Debugging bitflags: each option can be enabled individually.
|
| 58 | *
|
| 59 | * Note: only debug flags included in the ARCNET_DEBUG_MAX define will
|
| 60 | * actually be available. GCC will (at least, GCC 2.7.0 will) notice
|
| 61 | * lines using a BUGLVL not in ARCNET_DEBUG_MAX and automatically optimize
|
| 62 | * them out.
|
| 63 |
|
| 64 | #define D_NORMAL 1
|
| 65 | #define D_EXTRA 2
|
| 66 | #define D_INIT 4
|
| 67 | #define D_INIT_REASONS 8
|
| 68 | #define D_RECON 32
|
| 69 | #define D_PROTO 64
|
| 70 |
|
| 71 | #define D_DURING 128
|
| 72 | #define D_TX 256
|
| 73 | #define D_RX 512
|
| 74 | #define D_SKB 1024
|
| 75 | #define D_SKB_SIZE 2048
|
| 76 | #define D_TIMING 4096
|
| 77 | #define D_DEBUG 8192
|
| 78 |
|
| 79 | #ifndef ARCNET_DEBUG_MAX
|
| 80 | #define ARCNET_DEBUG_MAX (127)
|
| 81 | #endif
|
| 82 |
|
| 83 | #ifndef ARCNET_DEBUG
|
| 84 | #define ARCNET_DEBUG (D_NORMAL|D_EXTRA)
|
| 85 | #endif
|
| 86 | extern int arcnet_debug;
|
| 87 |
|
| 88 |
|
| 89 | #define BUGLVL(x) if ((ARCNET_DEBUG_MAX)&arcnet_debug&(x))
|
| 90 | #define BUGMSG2(x,msg,args...) do { BUGLVL(x) printk(msg, ## args); } while (0)
|
| 91 | #define BUGMSG(x,msg,args...) \
|
| 92 | BUGMSG2(x, "%s%6s: " msg, \
|
| 93 | x==D_NORMAL ? KERN_WARNING \
|
| 94 | : x < D_DURING ? KERN_INFO : KERN_DEBUG, \
|
| 95 | dev->name , ## args)
|
| 96 |
|
| 97 |
|
| 98 | #define TIME(name, bytes, call) BUGLVL(D_TIMING) { \
|
| 99 | unsigned long _x, _y; \
|
| 100 | _x = get_cycles(); \
|
| 101 | call; \
|
| 102 | _y = get_cycles(); \
|
| 103 | BUGMSG(D_TIMING, \
|
| 104 | "%s: %d bytes in %lu cycles == " \
|
| 105 | "%lu Kbytes/100Mcycle\n",\
|
| 106 | name, bytes, _y - _x, \
|
| 107 | 100000000 / 1024 * bytes / (_y - _x + 1));\
|
| 108 | } \
|
| 109 | else { \
|
| 110 | call;\
|
| 111 | }
|
| 112 |
|
| 113 |
|
| 114 | |
| 115 | * Time needed to reset the card - in ms (milliseconds). This works on my
|
| 116 | * SMC PC100. I can't find a reference that tells me just how long I
|
| 117 | * should wait.
|
| 118 |
|
| 119 | #define RESETtime (300)
|
| 120 |
|
| 121 | |
| 122 | * These are the max/min lengths of packet payload, not including the
|
| 123 | * arc_hardware header, but definitely including the soft header.
|
| 124 | *
|
| 125 | * Note: packet sizes 254, 255, 256 are impossible because of the way
|
| 126 | * ARCnet registers work That's why RFC1201 defines "exception" packets.
|
| 127 | * In non-RFC1201 protocols, we have to just tack some extra bytes on the
|
| 128 | * end.
|
| 129 |
|
| 130 | #define MTU 253
|
| 131 | #define MinTU 257
|
| 132 | #define XMTU 508
|
| 133 |
|
| 134 |
|
| 135 | #define TXFREEflag 0x01
|
| 136 | #define TXACKflag 0x02
|
| 137 | #define RECONflag 0x04
|
| 138 | #define TESTflag 0x08
|
| 139 | #define EXCNAKflag 0x08
|
| 140 | #define RESETflag 0x10
|
| 141 | #define RES1flag 0x20
|
| 142 | #define RES2flag 0x40
|
| 143 | #define NORXflag 0x80
|
| 144 |
|
| 145 |
|
| 146 | #define AUTOINCflag 0x40
|
| 147 | #define IOMAPflag 0x02
|
| 148 | #define ENABLE16flag 0x80
|
| 149 |
|
| 150 | |
| 151 | * 0-2 command
|
| 152 | * 3-4 page number (for enable rcv/xmt command)
|
| 153 | * 7 receive broadcasts
|
| 154 |
|
| 155 | #define NOTXcmd 0x01
|
| 156 | #define NORXcmd 0x02
|
| 157 | #define TXcmd 0x03
|
| 158 | #define RXcmd 0x04
|
| 159 | #define CONFIGcmd 0x05
|
| 160 | #define CFLAGScmd 0x06
|
| 161 | #define TESTcmd 0x07
|
| 162 |
|
| 163 |
|
| 164 | #define RESETclear 0x08
|
| 165 | #define CONFIGclear 0x10
|
| 166 |
|
| 167 | #define EXCNAKclear 0x0E
|
| 168 |
|
| 169 |
|
| 170 | #define TESTload 0x08
|
| 171 |
|
| 172 |
|
| 173 | #define TESTvalue 0321
|
| 174 |
|
| 175 |
|
| 176 | #define RXbcasts 0x80
|
| 177 |
|
| 178 |
|
| 179 | #define NORMALconf 0x00
|
| 180 | #define EXTconf 0x08
|
| 181 |
|
| 182 | |
| 183 | * (currently only used by com20020pci)
|
| 184 |
|
| 185 | #define ARC_IS_5MBIT 1
|
| 186 | #define ARC_CAN_10MBIT 2 |
| 187 | but default is 2.5MBit.
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 | struct ArcProto {
|
| 192 | char suffix;
|
| 193 | int mtu;
|
| 194 | int is_ip;
|
| 195 |
|
| 196 | void (*rx) (struct net_device * dev, int bufnum,
|
| 197 | struct archdr * pkthdr, int length);
|
| 198 | int (*build_header) (struct sk_buff * skb, struct net_device *dev,
|
| 199 | unsigned short ethproto, uint8_t daddr);
|
| 200 |
|
| 201 |
|
| 202 | int (*prepare_tx) (struct net_device * dev, struct archdr * pkt, int length,
|
| 203 | int bufnum);
|
| 204 | int (*continue_tx) (struct net_device * dev, int bufnum);
|
| 205 | int (*ack_tx) (struct net_device * dev, int acked);
|
| 206 | };
|
| 207 |
|
| 208 | extern struct ArcProto *arc_proto_map[256], *arc_proto_default,
|
| 209 | *arc_bcast_proto, *arc_raw_proto;
|
| 210 |
|
| 211 |
|
| 212 | |
| 213 | * "Incoming" is information needed for each address that could be sending
|
| 214 | * to us. Mostly for partially-received split packets.
|
| 215 |
|
| 216 | struct Incoming {
|
| 217 | struct sk_buff *skb;
|
| 218 | __be16 sequence;
|
| 219 | uint8_t lastpacket,
|
| 220 | numpackets;
|
| 221 | };
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 | struct Outgoing {
|
| 226 | struct ArcProto *proto; |
| 227 | * if NULL, no packet is pending.
|
| 228 |
|
| 229 | struct sk_buff *skb;
|
| 230 | struct archdr *pkt;
|
| 231 | uint16_t length,
|
| 232 | dataleft,
|
| 233 | segnum,
|
| 234 | numsegs;
|
| 235 | };
|
| 236 |
|
| 237 |
|
| 238 | struct arcnet_local {
|
| 239 | uint8_t config,
|
| 240 | timeout,
|
| 241 | backplane,
|
| 242 | clockp,
|
| 243 | clockm,
|
| 244 | setup,
|
| 245 | setup2,
|
| 246 | intmask;
|
| 247 | uint8_t default_proto[256];
|
| 248 | int cur_tx,
|
| 249 | next_tx,
|
| 250 | cur_rx;
|
| 251 | int lastload_dest,
|
| 252 | lasttrans_dest;
|
| 253 | int timed_out;
|
| 254 | unsigned long last_timeout;
|
| 255 | char *card_name;
|
| 256 | int card_flags;
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 | spinlock_t lock;
|
| 261 |
|
| 262 | |
| 263 | * Buffer management: an ARCnet card has 4 x 512-byte buffers, each of
|
| 264 | * which can be used for either sending or receiving. The new dynamic
|
| 265 | * buffer management routines use a simple circular queue of available
|
| 266 | * buffers, and take them as they're needed. This way, we simplify
|
| 267 | * situations in which we (for example) want to pre-load a transmit
|
| 268 | * buffer, or start receiving while we copy a received packet to
|
| 269 | * memory.
|
| 270 | *
|
| 271 | * The rules: only the interrupt handler is allowed to _add_ buffers to
|
| 272 | * the queue; thus, this doesn't require a lock. Both the interrupt
|
| 273 | * handler and the transmit function will want to _remove_ buffers, so
|
| 274 | * we need to handle the situation where they try to do it at the same
|
| 275 | * time.
|
| 276 | *
|
| 277 | * If next_buf == first_free_buf, the queue is empty. Since there are
|
| 278 | * only four possible buffers, the queue should never be full.
|
| 279 |
|
| 280 | atomic_t buf_lock;
|
| 281 | int buf_queue[5];
|
| 282 | int next_buf, first_free_buf;
|
| 283 |
|
| 284 |
|
| 285 | unsigned long first_recon;
|
| 286 | unsigned long last_recon;
|
| 287 | int num_recons;
|
| 288 | bool network_down;
|
| 289 |
|
| 290 | bool excnak_pending;
|
| 291 |
|
| 292 | struct {
|
| 293 | uint16_t sequence;
|
| 294 | __be16 aborted_seq;
|
| 295 |
|
| 296 | struct Incoming incoming[256];
|
| 297 | } rfc1201;
|
| 298 |
|
| 299 |
|
| 300 | struct Outgoing outgoing;
|
| 301 |
|
| 302 |
|
| 303 | struct {
|
| 304 | struct module *owner;
|
| 305 | void (*command) (struct net_device * dev, int cmd);
|
| 306 | int (*status) (struct net_device * dev);
|
| 307 | void (*intmask) (struct net_device * dev, int mask);
|
| 308 | bool (*reset) (struct net_device * dev, bool really_reset);
|
| 309 | void (*open) (struct net_device * dev);
|
| 310 | void (*close) (struct net_device * dev);
|
| 311 |
|
| 312 | void (*copy_to_card) (struct net_device * dev, int bufnum, int offset,
|
| 313 | void *buf, int count);
|
| 314 | void (*copy_from_card) (struct net_device * dev, int bufnum, int offset,
|
| 315 | void *buf, int count);
|
| 316 | } hw;
|
| 317 |
|
| 318 | void __iomem *mem_start;
|
| 319 | };
|
| 320 |
|
| 321 |
|
| 322 | #define ARCRESET(x) (lp->hw.reset(dev, (x)))
|
| 323 | #define ACOMMAND(x) (lp->hw.command(dev, (x)))
|
| 324 | #define ASTATUS() (lp->hw.status(dev))
|
| 325 | #define AINTMASK(x) (lp->hw.intmask(dev, (x)))
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 | #if ARCNET_DEBUG_MAX & D_SKB
|
| 330 | void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc);
|
| 331 | #else
|
| 332 | #define arcnet_dump_skb(dev,skb,desc) ;
|
| 333 | #endif
|
| 334 |
|
| 335 | void arcnet_unregister_proto(struct ArcProto *proto);
|
| 336 | irqreturn_t arcnet_interrupt(int irq, void *dev_id);
|
| 337 | struct net_device *alloc_arcdev(const char *name);
|
| 338 |
|
| 339 | int arcnet_open(struct net_device *dev);
|
| 340 | int arcnet_close(struct net_device *dev);
|
| 341 | netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
|
| 342 | struct net_device *dev);
|
| 343 | void arcnet_timeout(struct net_device *dev);
|
| 344 |
|
| 345 | #endif
|
| 346 | #endif
|