ctcm_main.h 7.2 KB

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