arcdevice.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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. #include <asm/timex.h>
  19. #include <linux/if_arcnet.h>
  20. #ifdef __KERNEL__
  21. #include <linux/irqreturn.h>
  22. /*
  23. * RECON_THRESHOLD is the maximum number of RECON messages to receive
  24. * within one minute before printing a "cabling problem" warning. The
  25. * default value should be fine.
  26. *
  27. * After that, a "cabling restored" message will be printed on the next IRQ
  28. * if no RECON messages have been received for 10 seconds.
  29. *
  30. * Do not define RECON_THRESHOLD at all if you want to disable this feature.
  31. */
  32. #define RECON_THRESHOLD 30
  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. /* Display warnings about the driver being an ALPHA version. */
  42. #undef ALPHA_WARNING
  43. /*
  44. * Debugging bitflags: each option can be enabled individually.
  45. *
  46. * Note: only debug flags included in the ARCNET_DEBUG_MAX define will
  47. * actually be available. GCC will (at least, GCC 2.7.0 will) notice
  48. * lines using a BUGLVL not in ARCNET_DEBUG_MAX and automatically optimize
  49. * them out.
  50. */
  51. #define D_NORMAL 1 /* important operational info */
  52. #define D_EXTRA 2 /* useful, but non-vital information */
  53. #define D_INIT 4 /* show init/probe messages */
  54. #define D_INIT_REASONS 8 /* show reasons for discarding probes */
  55. #define D_RECON 32 /* print a message whenever token is lost */
  56. #define D_PROTO 64 /* debug auto-protocol support */
  57. /* debug levels below give LOTS of output during normal operation! */
  58. #define D_DURING 128 /* trace operations (including irq's) */
  59. #define D_TX 256 /* show tx packets */
  60. #define D_RX 512 /* show rx packets */
  61. #define D_SKB 1024 /* show skb's */
  62. #define D_SKB_SIZE 2048 /* show skb sizes */
  63. #define D_TIMING 4096 /* show time needed to copy buffers to card */
  64. #define D_DEBUG 8192 /* Very detailed debug line for line */
  65. #ifndef ARCNET_DEBUG_MAX
  66. #define ARCNET_DEBUG_MAX (127) /* change to ~0 if you want detailed debugging */
  67. #endif
  68. #ifndef ARCNET_DEBUG
  69. #define ARCNET_DEBUG (D_NORMAL | D_EXTRA)
  70. #endif
  71. extern int arcnet_debug;
  72. #define BUGLVL(x) ((x) & ARCNET_DEBUG_MAX & arcnet_debug)
  73. /* macros to simplify debug checking */
  74. #define arc_printk(x, dev, fmt, ...) \
  75. do { \
  76. if (BUGLVL(x)) { \
  77. if ((x) == D_NORMAL) \
  78. netdev_warn(dev, fmt, ##__VA_ARGS__); \
  79. else if ((x) < D_DURING) \
  80. netdev_info(dev, fmt, ##__VA_ARGS__); \
  81. else \
  82. netdev_dbg(dev, fmt, ##__VA_ARGS__); \
  83. } \
  84. } while (0)
  85. #define arc_cont(x, fmt, ...) \
  86. do { \
  87. if (BUGLVL(x)) \
  88. pr_cont(fmt, ##__VA_ARGS__); \
  89. } while (0)
  90. /* see how long a function call takes to run, expressed in CPU cycles */
  91. #define TIME(dev, name, bytes, call) \
  92. do { \
  93. if (BUGLVL(D_TIMING)) { \
  94. unsigned long _x, _y; \
  95. _x = get_cycles(); \
  96. call; \
  97. _y = get_cycles(); \
  98. arc_printk(D_TIMING, dev, \
  99. "%s: %d bytes in %lu cycles == %lu Kbytes/100Mcycle\n", \
  100. name, bytes, _y - _x, \
  101. 100000000 / 1024 * bytes / (_y - _x + 1)); \
  102. } else { \
  103. call; \
  104. } \
  105. } while (0)
  106. /*
  107. * Time needed to reset the card - in ms (milliseconds). This works on my
  108. * SMC PC100. I can't find a reference that tells me just how long I
  109. * should wait.
  110. */
  111. #define RESETtime (300)
  112. /*
  113. * These are the max/min lengths of packet payload, not including the
  114. * arc_hardware header, but definitely including the soft header.
  115. *
  116. * Note: packet sizes 254, 255, 256 are impossible because of the way
  117. * ARCnet registers work That's why RFC1201 defines "exception" packets.
  118. * In non-RFC1201 protocols, we have to just tack some extra bytes on the
  119. * end.
  120. */
  121. #define MTU 253 /* normal packet max size */
  122. #define MinTU 257 /* extended packet min size */
  123. #define XMTU 508 /* extended packet max size */
  124. /* status/interrupt mask bit fields */
  125. #define TXFREEflag 0x01 /* transmitter available */
  126. #define TXACKflag 0x02 /* transmitted msg. ackd */
  127. #define RECONflag 0x04 /* network reconfigured */
  128. #define TESTflag 0x08 /* test flag */
  129. #define EXCNAKflag 0x08 /* excesive nak flag */
  130. #define RESETflag 0x10 /* power-on-reset */
  131. #define RES1flag 0x20 /* reserved - usually set by jumper */
  132. #define RES2flag 0x40 /* reserved - usually set by jumper */
  133. #define NORXflag 0x80 /* receiver inhibited */
  134. /* Flags used for IO-mapped memory operations */
  135. #define AUTOINCflag 0x40 /* Increase location with each access */
  136. #define IOMAPflag 0x02 /* (for 90xx) Use IO mapped memory, not mmap */
  137. #define ENABLE16flag 0x80 /* (for 90xx) Enable 16-bit mode */
  138. /* in the command register, the following bits have these meanings:
  139. * 0-2 command
  140. * 3-4 page number (for enable rcv/xmt command)
  141. * 7 receive broadcasts
  142. */
  143. #define NOTXcmd 0x01 /* disable transmitter */
  144. #define NORXcmd 0x02 /* disable receiver */
  145. #define TXcmd 0x03 /* enable transmitter */
  146. #define RXcmd 0x04 /* enable receiver */
  147. #define CONFIGcmd 0x05 /* define configuration */
  148. #define CFLAGScmd 0x06 /* clear flags */
  149. #define TESTcmd 0x07 /* load test flags */
  150. #define STARTIOcmd 0x18 /* start internal operation */
  151. /* flags for "clear flags" command */
  152. #define RESETclear 0x08 /* power-on-reset */
  153. #define CONFIGclear 0x10 /* system reconfigured */
  154. #define EXCNAKclear 0x0E /* Clear and acknowledge the excive nak bit */
  155. /* flags for "load test flags" command */
  156. #define TESTload 0x08 /* test flag (diagnostic) */
  157. /* byte deposited into first address of buffers on reset */
  158. #define TESTvalue 0321 /* that's octal for 0xD1 :) */
  159. /* for "enable receiver" command */
  160. #define RXbcasts 0x80 /* receive broadcasts */
  161. /* flags for "define configuration" command */
  162. #define NORMALconf 0x00 /* 1-249 byte packets */
  163. #define EXTconf 0x08 /* 250-504 byte packets */
  164. /* card feature flags, set during auto-detection.
  165. * (currently only used by com20020pci)
  166. */
  167. #define ARC_IS_5MBIT 1 /* card default speed is 5MBit */
  168. #define ARC_CAN_10MBIT 2 /* card uses COM20022, supporting 10MBit,
  169. but default is 2.5MBit. */
  170. /* information needed to define an encapsulation driver */
  171. struct ArcProto {
  172. char suffix; /* a for RFC1201, e for ether-encap, etc. */
  173. int mtu; /* largest possible packet */
  174. int is_ip; /* This is a ip plugin - not a raw thing */
  175. void (*rx)(struct net_device *dev, int bufnum,
  176. struct archdr *pkthdr, int length);
  177. int (*build_header)(struct sk_buff *skb, struct net_device *dev,
  178. unsigned short ethproto, uint8_t daddr);
  179. /* these functions return '1' if the skb can now be freed */
  180. int (*prepare_tx)(struct net_device *dev, struct archdr *pkt,
  181. int length, int bufnum);
  182. int (*continue_tx)(struct net_device *dev, int bufnum);
  183. int (*ack_tx)(struct net_device *dev, int acked);
  184. };
  185. extern struct ArcProto *arc_proto_map[256], *arc_proto_default,
  186. *arc_bcast_proto, *arc_raw_proto;
  187. /*
  188. * "Incoming" is information needed for each address that could be sending
  189. * to us. Mostly for partially-received split packets.
  190. */
  191. struct Incoming {
  192. struct sk_buff *skb; /* packet data buffer */
  193. __be16 sequence; /* sequence number of assembly */
  194. uint8_t lastpacket, /* number of last packet (from 1) */
  195. numpackets; /* number of packets in split */
  196. };
  197. /* only needed for RFC1201 */
  198. struct Outgoing {
  199. struct ArcProto *proto; /* protocol driver that owns this:
  200. * if NULL, no packet is pending.
  201. */
  202. struct sk_buff *skb; /* buffer from upper levels */
  203. struct archdr *pkt; /* a pointer into the skb */
  204. uint16_t length, /* bytes total */
  205. dataleft, /* bytes left */
  206. segnum, /* segment being sent */
  207. numsegs; /* number of segments */
  208. };
  209. #define ARCNET_LED_NAME_SZ (IFNAMSIZ + 6)
  210. struct arcnet_local {
  211. uint8_t config, /* current value of CONFIG register */
  212. timeout, /* Extended timeout for COM20020 */
  213. backplane, /* Backplane flag for COM20020 */
  214. clockp, /* COM20020 clock divider */
  215. clockm, /* COM20020 clock multiplier flag */
  216. setup, /* Contents of setup1 register */
  217. setup2, /* Contents of setup2 register */
  218. intmask; /* current value of INTMASK register */
  219. uint8_t default_proto[256]; /* default encap to use for each host */
  220. int cur_tx, /* buffer used by current transmit, or -1 */
  221. next_tx, /* buffer where a packet is ready to send */
  222. cur_rx; /* current receive buffer */
  223. int lastload_dest, /* can last loaded packet be acked? */
  224. lasttrans_dest; /* can last TX'd packet be acked? */
  225. int timed_out; /* need to process TX timeout and drop packet */
  226. unsigned long last_timeout; /* time of last reported timeout */
  227. char *card_name; /* card ident string */
  228. int card_flags; /* special card features */
  229. /* On preemtive and SMB a lock is needed */
  230. spinlock_t lock;
  231. struct led_trigger *tx_led_trig;
  232. char tx_led_trig_name[ARCNET_LED_NAME_SZ];
  233. struct led_trigger *recon_led_trig;
  234. char recon_led_trig_name[ARCNET_LED_NAME_SZ];
  235. struct timer_list timer;
  236. /*
  237. * Buffer management: an ARCnet card has 4 x 512-byte buffers, each of
  238. * which can be used for either sending or receiving. The new dynamic
  239. * buffer management routines use a simple circular queue of available
  240. * buffers, and take them as they're needed. This way, we simplify
  241. * situations in which we (for example) want to pre-load a transmit
  242. * buffer, or start receiving while we copy a received packet to
  243. * memory.
  244. *
  245. * The rules: only the interrupt handler is allowed to _add_ buffers to
  246. * the queue; thus, this doesn't require a lock. Both the interrupt
  247. * handler and the transmit function will want to _remove_ buffers, so
  248. * we need to handle the situation where they try to do it at the same
  249. * time.
  250. *
  251. * If next_buf == first_free_buf, the queue is empty. Since there are
  252. * only four possible buffers, the queue should never be full.
  253. */
  254. atomic_t buf_lock;
  255. int buf_queue[5];
  256. int next_buf, first_free_buf;
  257. /* network "reconfiguration" handling */
  258. unsigned long first_recon; /* time of "first" RECON message to count */
  259. unsigned long last_recon; /* time of most recent RECON */
  260. int num_recons; /* number of RECONs between first and last. */
  261. int network_down; /* do we think the network is down? */
  262. int excnak_pending; /* We just got an excesive nak interrupt */
  263. struct {
  264. uint16_t sequence; /* sequence number (incs with each packet) */
  265. __be16 aborted_seq;
  266. struct Incoming incoming[256]; /* one from each address */
  267. } rfc1201;
  268. /* really only used by rfc1201, but we'll pretend it's not */
  269. struct Outgoing outgoing; /* packet currently being sent */
  270. /* hardware-specific functions */
  271. struct {
  272. struct module *owner;
  273. void (*command)(struct net_device *dev, int cmd);
  274. int (*status)(struct net_device *dev);
  275. void (*intmask)(struct net_device *dev, int mask);
  276. int (*reset)(struct net_device *dev, int really_reset);
  277. void (*open)(struct net_device *dev);
  278. void (*close)(struct net_device *dev);
  279. void (*datatrigger) (struct net_device * dev, int enable);
  280. void (*recontrigger) (struct net_device * dev, int enable);
  281. void (*copy_to_card)(struct net_device *dev, int bufnum,
  282. int offset, void *buf, int count);
  283. void (*copy_from_card)(struct net_device *dev, int bufnum,
  284. int offset, void *buf, int count);
  285. } hw;
  286. void __iomem *mem_start; /* pointer to ioremap'ed MMIO */
  287. };
  288. enum arcnet_led_event {
  289. ARCNET_LED_EVENT_RECON,
  290. ARCNET_LED_EVENT_OPEN,
  291. ARCNET_LED_EVENT_STOP,
  292. ARCNET_LED_EVENT_TX,
  293. };
  294. void arcnet_led_event(struct net_device *netdev, enum arcnet_led_event event);
  295. void devm_arcnet_led_init(struct net_device *netdev, int index, int subid);
  296. #if ARCNET_DEBUG_MAX & D_SKB
  297. void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc);
  298. #else
  299. static inline
  300. void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc)
  301. {
  302. }
  303. #endif
  304. void arcnet_unregister_proto(struct ArcProto *proto);
  305. irqreturn_t arcnet_interrupt(int irq, void *dev_id);
  306. struct net_device *alloc_arcdev(const char *name);
  307. int arcnet_open(struct net_device *dev);
  308. int arcnet_close(struct net_device *dev);
  309. netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
  310. struct net_device *dev);
  311. void arcnet_timeout(struct net_device *dev);
  312. /* I/O equivalents */
  313. #ifdef CONFIG_SA1100_CT6001
  314. #define BUS_ALIGN 2 /* 8 bit device on a 16 bit bus - needs padding */
  315. #else
  316. #define BUS_ALIGN 1
  317. #endif
  318. /* addr and offset allow register like names to define the actual IO address.
  319. * A configuration option multiplies the offset for alignment.
  320. */
  321. #define arcnet_inb(addr, offset) \
  322. inb((addr) + BUS_ALIGN * (offset))
  323. #define arcnet_outb(value, addr, offset) \
  324. outb(value, (addr) + BUS_ALIGN * (offset))
  325. #define arcnet_insb(addr, offset, buffer, count) \
  326. insb((addr) + BUS_ALIGN * (offset), buffer, count)
  327. #define arcnet_outsb(addr, offset, buffer, count) \
  328. outsb((addr) + BUS_ALIGN * (offset), buffer, count)
  329. #define arcnet_readb(addr, offset) \
  330. readb((addr) + (offset))
  331. #define arcnet_writeb(value, addr, offset) \
  332. writeb(value, (addr) + (offset))
  333. #endif /* __KERNEL__ */
  334. #endif /* _LINUX_ARCDEVICE_H */