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