arcdevice.h 14 KB

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