ctcm_main.h 6.9 KB

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