arcdevice.h 14 KB

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