ctcmain.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * CTC / ESCON network driver
  3. *
  4. * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
  5. * Author(s): Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
  6. Peter Tiedemann (ptiedem@de.ibm.com)
  7. *
  8. *
  9. * Documentation used:
  10. * - Principles of Operation (IBM doc#: SA22-7201-06)
  11. * - Common IO/-Device Commands and Self Description (IBM doc#: SA22-7204-02)
  12. * - Common IO/-Device Commands and Self Description (IBM doc#: SN22-5535)
  13. * - ESCON Channel-to-Channel Adapter (IBM doc#: SA22-7203-00)
  14. * - ESCON I/O Interface (IBM doc#: SA22-7202-029
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2, or (at your option)
  19. * any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. *
  30. */
  31. #ifndef _CTCMAIN_H_
  32. #define _CTCMAIN_H_
  33. #include <asm/ccwdev.h>
  34. #include <asm/ccwgroup.h>
  35. #include "ctctty.h"
  36. #include "fsm.h"
  37. #include "cu3088.h"
  38. /**
  39. * CCW commands, used in this driver.
  40. */
  41. #define CCW_CMD_WRITE 0x01
  42. #define CCW_CMD_READ 0x02
  43. #define CCW_CMD_SET_EXTENDED 0xc3
  44. #define CCW_CMD_PREPARE 0xe3
  45. #define CTC_PROTO_S390 0
  46. #define CTC_PROTO_LINUX 1
  47. #define CTC_PROTO_LINUX_TTY 2
  48. #define CTC_PROTO_OS390 3
  49. #define CTC_PROTO_MAX 3
  50. #define CTC_BUFSIZE_LIMIT 65535
  51. #define CTC_BUFSIZE_DEFAULT 32768
  52. #define CTC_TIMEOUT_5SEC 5000
  53. #define CTC_INITIAL_BLOCKLEN 2
  54. #define READ 0
  55. #define WRITE 1
  56. #define CTC_ID_SIZE BUS_ID_SIZE+3
  57. struct ctc_profile {
  58. unsigned long maxmulti;
  59. unsigned long maxcqueue;
  60. unsigned long doios_single;
  61. unsigned long doios_multi;
  62. unsigned long txlen;
  63. unsigned long tx_time;
  64. struct timespec send_stamp;
  65. };
  66. /**
  67. * Definition of one channel
  68. */
  69. struct channel {
  70. /**
  71. * Pointer to next channel in list.
  72. */
  73. struct channel *next;
  74. char id[CTC_ID_SIZE];
  75. struct ccw_device *cdev;
  76. /**
  77. * Type of this channel.
  78. * CTC/A or Escon for valid channels.
  79. */
  80. enum channel_types type;
  81. /**
  82. * Misc. flags. See CHANNEL_FLAGS_... below
  83. */
  84. __u32 flags;
  85. /**
  86. * The protocol of this channel
  87. */
  88. __u16 protocol;
  89. /**
  90. * I/O and irq related stuff
  91. */
  92. struct ccw1 *ccw;
  93. struct irb *irb;
  94. /**
  95. * RX/TX buffer size
  96. */
  97. int max_bufsize;
  98. /**
  99. * Transmit/Receive buffer.
  100. */
  101. struct sk_buff *trans_skb;
  102. /**
  103. * Universal I/O queue.
  104. */
  105. struct sk_buff_head io_queue;
  106. /**
  107. * TX queue for collecting skb's during busy.
  108. */
  109. struct sk_buff_head collect_queue;
  110. /**
  111. * Amount of data in collect_queue.
  112. */
  113. int collect_len;
  114. /**
  115. * spinlock for collect_queue and collect_len
  116. */
  117. spinlock_t collect_lock;
  118. /**
  119. * Timer for detecting unresposive
  120. * I/O operations.
  121. */
  122. fsm_timer timer;
  123. /**
  124. * Retry counter for misc. operations.
  125. */
  126. int retry;
  127. /**
  128. * The finite state machine of this channel
  129. */
  130. fsm_instance *fsm;
  131. /**
  132. * The corresponding net_device this channel
  133. * belongs to.
  134. */
  135. struct net_device *netdev;
  136. struct ctc_profile prof;
  137. unsigned char *trans_skb_data;
  138. __u16 logflags;
  139. };
  140. #define CHANNEL_FLAGS_READ 0
  141. #define CHANNEL_FLAGS_WRITE 1
  142. #define CHANNEL_FLAGS_INUSE 2
  143. #define CHANNEL_FLAGS_BUFSIZE_CHANGED 4
  144. #define CHANNEL_FLAGS_FAILED 8
  145. #define CHANNEL_FLAGS_WAITIRQ 16
  146. #define CHANNEL_FLAGS_RWMASK 1
  147. #define CHANNEL_DIRECTION(f) (f & CHANNEL_FLAGS_RWMASK)
  148. #define LOG_FLAG_ILLEGALPKT 1
  149. #define LOG_FLAG_ILLEGALSIZE 2
  150. #define LOG_FLAG_OVERRUN 4
  151. #define LOG_FLAG_NOMEM 8
  152. #define CTC_LOGLEVEL_INFO 1
  153. #define CTC_LOGLEVEL_NOTICE 2
  154. #define CTC_LOGLEVEL_WARN 4
  155. #define CTC_LOGLEVEL_EMERG 8
  156. #define CTC_LOGLEVEL_ERR 16
  157. #define CTC_LOGLEVEL_DEBUG 32
  158. #define CTC_LOGLEVEL_CRIT 64
  159. #define CTC_LOGLEVEL_DEFAULT \
  160. (CTC_LOGLEVEL_INFO | CTC_LOGLEVEL_NOTICE | CTC_LOGLEVEL_WARN | CTC_LOGLEVEL_CRIT)
  161. #define CTC_LOGLEVEL_MAX ((CTC_LOGLEVEL_CRIT<<1)-1)
  162. #define ctc_pr_debug(fmt, arg...) \
  163. do { if (loglevel & CTC_LOGLEVEL_DEBUG) printk(KERN_DEBUG fmt,##arg); } while (0)
  164. #define ctc_pr_info(fmt, arg...) \
  165. do { if (loglevel & CTC_LOGLEVEL_INFO) printk(KERN_INFO fmt,##arg); } while (0)
  166. #define ctc_pr_notice(fmt, arg...) \
  167. do { if (loglevel & CTC_LOGLEVEL_NOTICE) printk(KERN_NOTICE fmt,##arg); } while (0)
  168. #define ctc_pr_warn(fmt, arg...) \
  169. do { if (loglevel & CTC_LOGLEVEL_WARN) printk(KERN_WARNING fmt,##arg); } while (0)
  170. #define ctc_pr_emerg(fmt, arg...) \
  171. do { if (loglevel & CTC_LOGLEVEL_EMERG) printk(KERN_EMERG fmt,##arg); } while (0)
  172. #define ctc_pr_err(fmt, arg...) \
  173. do { if (loglevel & CTC_LOGLEVEL_ERR) printk(KERN_ERR fmt,##arg); } while (0)
  174. #define ctc_pr_crit(fmt, arg...) \
  175. do { if (loglevel & CTC_LOGLEVEL_CRIT) printk(KERN_CRIT fmt,##arg); } while (0)
  176. struct ctc_priv {
  177. struct net_device_stats stats;
  178. unsigned long tbusy;
  179. /**
  180. * The finite state machine of this interface.
  181. */
  182. fsm_instance *fsm;
  183. /**
  184. * The protocol of this device
  185. */
  186. __u16 protocol;
  187. /**
  188. * Timer for restarting after I/O Errors
  189. */
  190. fsm_timer restart_timer;
  191. int buffer_size;
  192. struct channel *channel[2];
  193. };
  194. /**
  195. * Definition of our link level header.
  196. */
  197. struct ll_header {
  198. __u16 length;
  199. __u16 type;
  200. __u16 unused;
  201. };
  202. #define LL_HEADER_LENGTH (sizeof(struct ll_header))
  203. /**
  204. * Compatibility macros for busy handling
  205. * of network devices.
  206. */
  207. static __inline__ void
  208. ctc_clear_busy(struct net_device * dev)
  209. {
  210. clear_bit(0, &(((struct ctc_priv *) dev->priv)->tbusy));
  211. if (((struct ctc_priv *)dev->priv)->protocol != CTC_PROTO_LINUX_TTY)
  212. netif_wake_queue(dev);
  213. }
  214. static __inline__ int
  215. ctc_test_and_set_busy(struct net_device * dev)
  216. {
  217. if (((struct ctc_priv *)dev->priv)->protocol != CTC_PROTO_LINUX_TTY)
  218. netif_stop_queue(dev);
  219. return test_and_set_bit(0, &((struct ctc_priv *) dev->priv)->tbusy);
  220. }
  221. #endif