ctcmain.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 <linux/skbuff.h>
  36. #include <linux/netdevice.h>
  37. #include "fsm.h"
  38. #include "cu3088.h"
  39. /**
  40. * CCW commands, used in this driver.
  41. */
  42. #define CCW_CMD_WRITE 0x01
  43. #define CCW_CMD_READ 0x02
  44. #define CCW_CMD_SET_EXTENDED 0xc3
  45. #define CCW_CMD_PREPARE 0xe3
  46. #define CTC_PROTO_S390 0
  47. #define CTC_PROTO_LINUX 1
  48. #define CTC_PROTO_OS390 3
  49. #define CTC_BUFSIZE_LIMIT 65535
  50. #define CTC_BUFSIZE_DEFAULT 32768
  51. #define CTC_TIMEOUT_5SEC 5000
  52. #define CTC_INITIAL_BLOCKLEN 2
  53. #define READ 0
  54. #define WRITE 1
  55. #define CTC_ID_SIZE BUS_ID_SIZE+3
  56. struct ctc_profile {
  57. unsigned long maxmulti;
  58. unsigned long maxcqueue;
  59. unsigned long doios_single;
  60. unsigned long doios_multi;
  61. unsigned long txlen;
  62. unsigned long tx_time;
  63. struct timespec send_stamp;
  64. };
  65. /**
  66. * Definition of one channel
  67. */
  68. struct channel {
  69. /**
  70. * Pointer to next channel in list.
  71. */
  72. struct channel *next;
  73. char id[CTC_ID_SIZE];
  74. struct ccw_device *cdev;
  75. /**
  76. * Type of this channel.
  77. * CTC/A or Escon for valid channels.
  78. */
  79. enum channel_types type;
  80. /**
  81. * Misc. flags. See CHANNEL_FLAGS_... below
  82. */
  83. __u32 flags;
  84. /**
  85. * The protocol of this channel
  86. */
  87. __u16 protocol;
  88. /**
  89. * I/O and irq related stuff
  90. */
  91. struct ccw1 *ccw;
  92. struct irb *irb;
  93. /**
  94. * RX/TX buffer size
  95. */
  96. int max_bufsize;
  97. /**
  98. * Transmit/Receive buffer.
  99. */
  100. struct sk_buff *trans_skb;
  101. /**
  102. * Universal I/O queue.
  103. */
  104. struct sk_buff_head io_queue;
  105. /**
  106. * TX queue for collecting skb's during busy.
  107. */
  108. struct sk_buff_head collect_queue;
  109. /**
  110. * Amount of data in collect_queue.
  111. */
  112. int collect_len;
  113. /**
  114. * spinlock for collect_queue and collect_len
  115. */
  116. spinlock_t collect_lock;
  117. /**
  118. * Timer for detecting unresposive
  119. * I/O operations.
  120. */
  121. fsm_timer timer;
  122. /**
  123. * Retry counter for misc. operations.
  124. */
  125. int retry;
  126. /**
  127. * The finite state machine of this channel
  128. */
  129. fsm_instance *fsm;
  130. /**
  131. * The corresponding net_device this channel
  132. * belongs to.
  133. */
  134. struct net_device *netdev;
  135. struct ctc_profile prof;
  136. unsigned char *trans_skb_data;
  137. __u16 logflags;
  138. };
  139. #define CHANNEL_FLAGS_READ 0
  140. #define CHANNEL_FLAGS_WRITE 1
  141. #define CHANNEL_FLAGS_INUSE 2
  142. #define CHANNEL_FLAGS_BUFSIZE_CHANGED 4
  143. #define CHANNEL_FLAGS_FAILED 8
  144. #define CHANNEL_FLAGS_WAITIRQ 16
  145. #define CHANNEL_FLAGS_RWMASK 1
  146. #define CHANNEL_DIRECTION(f) (f & CHANNEL_FLAGS_RWMASK)
  147. #define LOG_FLAG_ILLEGALPKT 1
  148. #define LOG_FLAG_ILLEGALSIZE 2
  149. #define LOG_FLAG_OVERRUN 4
  150. #define LOG_FLAG_NOMEM 8
  151. #define CTC_LOGLEVEL_INFO 1
  152. #define CTC_LOGLEVEL_NOTICE 2
  153. #define CTC_LOGLEVEL_WARN 4
  154. #define CTC_LOGLEVEL_EMERG 8
  155. #define CTC_LOGLEVEL_ERR 16
  156. #define CTC_LOGLEVEL_DEBUG 32
  157. #define CTC_LOGLEVEL_CRIT 64
  158. #define CTC_LOGLEVEL_DEFAULT \
  159. (CTC_LOGLEVEL_INFO | CTC_LOGLEVEL_NOTICE | CTC_LOGLEVEL_WARN | CTC_LOGLEVEL_CRIT)
  160. #define CTC_LOGLEVEL_MAX ((CTC_LOGLEVEL_CRIT<<1)-1)
  161. #define ctc_pr_debug(fmt, arg...) \
  162. do { if (loglevel & CTC_LOGLEVEL_DEBUG) printk(KERN_DEBUG fmt,##arg); } while (0)
  163. #define ctc_pr_info(fmt, arg...) \
  164. do { if (loglevel & CTC_LOGLEVEL_INFO) printk(KERN_INFO fmt,##arg); } while (0)
  165. #define ctc_pr_notice(fmt, arg...) \
  166. do { if (loglevel & CTC_LOGLEVEL_NOTICE) printk(KERN_NOTICE fmt,##arg); } while (0)
  167. #define ctc_pr_warn(fmt, arg...) \
  168. do { if (loglevel & CTC_LOGLEVEL_WARN) printk(KERN_WARNING fmt,##arg); } while (0)
  169. #define ctc_pr_emerg(fmt, arg...) \
  170. do { if (loglevel & CTC_LOGLEVEL_EMERG) printk(KERN_EMERG fmt,##arg); } while (0)
  171. #define ctc_pr_err(fmt, arg...) \
  172. do { if (loglevel & CTC_LOGLEVEL_ERR) printk(KERN_ERR fmt,##arg); } while (0)
  173. #define ctc_pr_crit(fmt, arg...) \
  174. do { if (loglevel & CTC_LOGLEVEL_CRIT) printk(KERN_CRIT fmt,##arg); } while (0)
  175. struct ctc_priv {
  176. struct net_device_stats stats;
  177. unsigned long tbusy;
  178. /**
  179. * The finite state machine of this interface.
  180. */
  181. fsm_instance *fsm;
  182. /**
  183. * The protocol of this device
  184. */
  185. __u16 protocol;
  186. /**
  187. * Timer for restarting after I/O Errors
  188. */
  189. fsm_timer restart_timer;
  190. int buffer_size;
  191. struct channel *channel[2];
  192. };
  193. /**
  194. * Definition of our link level header.
  195. */
  196. struct ll_header {
  197. __u16 length;
  198. __u16 type;
  199. __u16 unused;
  200. };
  201. #define LL_HEADER_LENGTH (sizeof(struct ll_header))
  202. /**
  203. * Compatibility macros for busy handling
  204. * of network devices.
  205. */
  206. static __inline__ void
  207. ctc_clear_busy(struct net_device * dev)
  208. {
  209. clear_bit(0, &(((struct ctc_priv *) dev->priv)->tbusy));
  210. netif_wake_queue(dev);
  211. }
  212. static __inline__ int
  213. ctc_test_and_set_busy(struct net_device * dev)
  214. {
  215. netif_stop_queue(dev);
  216. return test_and_set_bit(0, &((struct ctc_priv *) dev->priv)->tbusy);
  217. }
  218. #endif