ctcm_main.h 6.6 KB

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