ctcm_main.h 6.8 KB

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