ctcm_main.h 7.1 KB

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