arcdevice.h 12 KB

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