ctcm_main.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*
  2. * Copyright IBM Corp. 2001, 2007
  3. * Authors: Fritz Elfert (felfert@millenux.com)
  4. * Peter Tiedemann (ptiedem@de.ibm.com)
  5. */
  6. #ifndef _CTCM_MAIN_H_
  7. #define _CTCM_MAIN_H_
  8. #include <asm/ccwdev.h>
  9. #include <asm/ccwgroup.h>
  10. #include <linux/skbuff.h>
  11. #include <linux/netdevice.h>
  12. #include "fsm.h"
  13. #include "ctcm_dbug.h"
  14. #include "ctcm_mpc.h"
  15. #define CTC_DRIVER_NAME "ctcm"
  16. #define CTC_DEVICE_NAME "ctc"
  17. #define MPC_DEVICE_NAME "mpc"
  18. #define CTC_DEVICE_GENE CTC_DEVICE_NAME "%d"
  19. #define MPC_DEVICE_GENE MPC_DEVICE_NAME "%d"
  20. #define CHANNEL_FLAGS_READ 0
  21. #define CHANNEL_FLAGS_WRITE 1
  22. #define CHANNEL_FLAGS_INUSE 2
  23. #define CHANNEL_FLAGS_BUFSIZE_CHANGED 4
  24. #define CHANNEL_FLAGS_FAILED 8
  25. #define CHANNEL_FLAGS_WAITIRQ 16
  26. #define CHANNEL_FLAGS_RWMASK 1
  27. #define CHANNEL_DIRECTION(f) (f & CHANNEL_FLAGS_RWMASK)
  28. #define LOG_FLAG_ILLEGALPKT 1
  29. #define LOG_FLAG_ILLEGALSIZE 2
  30. #define LOG_FLAG_OVERRUN 4
  31. #define LOG_FLAG_NOMEM 8
  32. #define ctcm_pr_debug(fmt, arg...) printk(KERN_DEBUG fmt, ##arg)
  33. #define CTCM_PR_DEBUG(fmt, arg...) \
  34. do { \
  35. if (do_debug) \
  36. printk(KERN_DEBUG fmt, ##arg); \
  37. } while (0)
  38. #define CTCM_PR_DBGDATA(fmt, arg...) \
  39. do { \
  40. if (do_debug_data) \
  41. printk(KERN_DEBUG fmt, ##arg); \
  42. } while (0)
  43. #define CTCM_D3_DUMP(buf, len) \
  44. do { \
  45. if (do_debug_data) \
  46. ctcmpc_dumpit(buf, len); \
  47. } while (0)
  48. #define CTCM_CCW_DUMP(buf, len) \
  49. do { \
  50. if (do_debug_ccw) \
  51. ctcmpc_dumpit(buf, len); \
  52. } while (0)
  53. /**
  54. * Enum for classifying detected devices
  55. */
  56. enum ctcm_channel_types {
  57. /* Device is not a channel */
  58. ctcm_channel_type_none,
  59. /* Device is a CTC/A */
  60. ctcm_channel_type_parallel,
  61. /* Device is a FICON channel */
  62. ctcm_channel_type_ficon,
  63. /* Device is a ESCON channel */
  64. ctcm_channel_type_escon
  65. };
  66. /*
  67. * CCW commands, used in this driver.
  68. */
  69. #define CCW_CMD_WRITE 0x01
  70. #define CCW_CMD_READ 0x02
  71. #define CCW_CMD_NOOP 0x03
  72. #define CCW_CMD_TIC 0x08
  73. #define CCW_CMD_SENSE_CMD 0x14
  74. #define CCW_CMD_WRITE_CTL 0x17
  75. #define CCW_CMD_SET_EXTENDED 0xc3
  76. #define CCW_CMD_PREPARE 0xe3
  77. #define CTCM_PROTO_S390 0
  78. #define CTCM_PROTO_LINUX 1
  79. #define CTCM_PROTO_LINUX_TTY 2
  80. #define CTCM_PROTO_OS390 3
  81. #define CTCM_PROTO_MPC 4
  82. #define CTCM_PROTO_MAX 4
  83. #define CTCM_BUFSIZE_LIMIT 65535
  84. #define CTCM_BUFSIZE_DEFAULT 32768
  85. #define MPC_BUFSIZE_DEFAULT CTCM_BUFSIZE_LIMIT
  86. #define CTCM_TIME_1_SEC 1000
  87. #define CTCM_TIME_5_SEC 5000
  88. #define CTCM_TIME_10_SEC 10000
  89. #define CTCM_INITIAL_BLOCKLEN 2
  90. #define CTCM_READ 0
  91. #define CTCM_WRITE 1
  92. #define CTCM_ID_SIZE 20+3
  93. struct ctcm_profile {
  94. unsigned long maxmulti;
  95. unsigned long maxcqueue;
  96. unsigned long doios_single;
  97. unsigned long doios_multi;
  98. unsigned long txlen;
  99. unsigned long tx_time;
  100. unsigned long send_stamp;
  101. };
  102. /*
  103. * Definition of one channel
  104. */
  105. struct channel {
  106. struct channel *next;
  107. char id[CTCM_ID_SIZE];
  108. struct ccw_device *cdev;
  109. /*
  110. * Type of this channel.
  111. * CTC/A or Escon for valid channels.
  112. */
  113. enum ctcm_channel_types type;
  114. /*
  115. * Misc. flags. See CHANNEL_FLAGS_... below
  116. */
  117. __u32 flags;
  118. __u16 protocol; /* protocol of this channel (4 = MPC) */
  119. /*
  120. * I/O and irq related stuff
  121. */
  122. struct ccw1 *ccw;
  123. struct irb *irb;
  124. /*
  125. * RX/TX buffer size
  126. */
  127. int max_bufsize;
  128. struct sk_buff *trans_skb; /* transmit/receive buffer */
  129. struct sk_buff_head io_queue; /* universal I/O queue */
  130. struct tasklet_struct ch_tasklet; /* MPC ONLY */
  131. /*
  132. * TX queue for collecting skb's during busy.
  133. */
  134. struct sk_buff_head collect_queue;
  135. /*
  136. * Amount of data in collect_queue.
  137. */
  138. int collect_len;
  139. /*
  140. * spinlock for collect_queue and collect_len
  141. */
  142. spinlock_t collect_lock;
  143. /*
  144. * Timer for detecting unresposive
  145. * I/O operations.
  146. */
  147. fsm_timer timer;
  148. /* MPC ONLY section begin */
  149. __u32 th_seq_num; /* SNA TH seq number */
  150. __u8 th_seg;
  151. __u32 pdu_seq;
  152. struct sk_buff *xid_skb;
  153. char *xid_skb_data;
  154. struct th_header *xid_th;
  155. struct xid2 *xid;
  156. char *xid_id;
  157. struct th_header *rcvd_xid_th;
  158. struct xid2 *rcvd_xid;
  159. char *rcvd_xid_id;
  160. __u8 in_mpcgroup;
  161. fsm_timer sweep_timer;
  162. struct sk_buff_head sweep_queue;
  163. struct th_header *discontact_th;
  164. struct tasklet_struct ch_disc_tasklet;
  165. /* MPC ONLY section end */
  166. int retry; /* retry counter for misc. operations */
  167. fsm_instance *fsm; /* finite state machine of this channel */
  168. struct net_device *netdev; /* corresponding net_device */
  169. struct ctcm_profile prof;
  170. __u8 *trans_skb_data;
  171. __u16 logflags;
  172. __u8 sense_rc; /* last unit check sense code report control */
  173. };
  174. struct ctcm_priv {
  175. struct net_device_stats stats;
  176. unsigned long tbusy;
  177. /* The MPC group struct of this interface */
  178. struct mpc_group *mpcg; /* MPC only */
  179. struct xid2 *xid; /* MPC only */
  180. /* The finite state machine of this interface */
  181. fsm_instance *fsm;
  182. /* The protocol of this device */
  183. __u16 protocol;
  184. /* Timer for restarting after I/O Errors */
  185. fsm_timer restart_timer;
  186. int buffer_size; /* ctc only */
  187. struct channel *channel[2];
  188. };
  189. int ctcm_open(struct net_device *dev);
  190. int ctcm_close(struct net_device *dev);
  191. extern const struct attribute_group *ctcm_attr_groups[];
  192. /*
  193. * Compatibility macros for busy handling
  194. * of network devices.
  195. */
  196. static inline void ctcm_clear_busy_do(struct net_device *dev)
  197. {
  198. clear_bit(0, &(((struct ctcm_priv *)dev->ml_priv)->tbusy));
  199. netif_wake_queue(dev);
  200. }
  201. static inline void ctcm_clear_busy(struct net_device *dev)
  202. {
  203. struct mpc_group *grp;
  204. grp = ((struct ctcm_priv *)dev->ml_priv)->mpcg;
  205. if (!(grp && grp->in_sweep))
  206. ctcm_clear_busy_do(dev);
  207. }
  208. static inline int ctcm_test_and_set_busy(struct net_device *dev)
  209. {
  210. netif_stop_queue(dev);
  211. return test_and_set_bit(0,
  212. &(((struct ctcm_priv *)dev->ml_priv)->tbusy));
  213. }
  214. extern int loglevel;
  215. extern struct channel *channels;
  216. void ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb);
  217. /*
  218. * Functions related to setup and device detection.
  219. */
  220. static inline int ctcm_less_than(char *id1, char *id2)
  221. {
  222. unsigned long dev1, dev2;
  223. id1 = id1 + 5;
  224. id2 = id2 + 5;
  225. dev1 = simple_strtoul(id1, &id1, 16);
  226. dev2 = simple_strtoul(id2, &id2, 16);
  227. return (dev1 < dev2);
  228. }
  229. int ctcm_ch_alloc_buffer(struct channel *ch);
  230. static inline int ctcm_checkalloc_buffer(struct channel *ch)
  231. {
  232. if (ch->trans_skb == NULL)
  233. return ctcm_ch_alloc_buffer(ch);
  234. if (ch->flags & CHANNEL_FLAGS_BUFSIZE_CHANGED) {
  235. dev_kfree_skb(ch->trans_skb);
  236. return ctcm_ch_alloc_buffer(ch);
  237. }
  238. return 0;
  239. }
  240. struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv);
  241. /* test if protocol attribute (of struct ctcm_priv or struct channel)
  242. * has MPC protocol setting. Type is not checked
  243. */
  244. #define IS_MPC(p) ((p)->protocol == CTCM_PROTO_MPC)
  245. /* test if struct ctcm_priv of struct net_device has MPC protocol setting */
  246. #define IS_MPCDEV(dev) IS_MPC((struct ctcm_priv *)dev->ml_priv)
  247. static inline gfp_t gfp_type(void)
  248. {
  249. return in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
  250. }
  251. /*
  252. * Definition of our link level header.
  253. */
  254. struct ll_header {
  255. __u16 length;
  256. __u16 type;
  257. __u16 unused;
  258. };
  259. #define LL_HEADER_LENGTH (sizeof(struct ll_header))
  260. #endif