ctcm_fsms.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. * MPC additions :
  7. * Belinda Thompson (belindat@us.ibm.com)
  8. * Andy Richter (richtera@us.ibm.com)
  9. */
  10. #ifndef _CTCM_FSMS_H_
  11. #define _CTCM_FSMS_H_
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/slab.h>
  16. #include <linux/errno.h>
  17. #include <linux/types.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/timer.h>
  20. #include <linux/bitops.h>
  21. #include <linux/signal.h>
  22. #include <linux/string.h>
  23. #include <linux/ip.h>
  24. #include <linux/if_arp.h>
  25. #include <linux/tcp.h>
  26. #include <linux/skbuff.h>
  27. #include <linux/ctype.h>
  28. #include <net/dst.h>
  29. #include <linux/io.h>
  30. #include <asm/ccwdev.h>
  31. #include <asm/ccwgroup.h>
  32. #include <linux/uaccess.h>
  33. #include <asm/idals.h>
  34. #include "fsm.h"
  35. #include "ctcm_main.h"
  36. /*
  37. * Definitions for the channel statemachine(s) for ctc and ctcmpc
  38. *
  39. * To allow better kerntyping, prefix-less definitions for channel states
  40. * and channel events have been replaced :
  41. * ch_event... -> ctc_ch_event...
  42. * CH_EVENT... -> CTC_EVENT...
  43. * ch_state... -> ctc_ch_state...
  44. * CH_STATE... -> CTC_STATE...
  45. */
  46. /*
  47. * Events of the channel statemachine(s) for ctc and ctcmpc
  48. */
  49. enum ctc_ch_events {
  50. /*
  51. * Events, representing return code of
  52. * I/O operations (ccw_device_start, ccw_device_halt et al.)
  53. */
  54. CTC_EVENT_IO_SUCCESS,
  55. CTC_EVENT_IO_EBUSY,
  56. CTC_EVENT_IO_ENODEV,
  57. CTC_EVENT_IO_UNKNOWN,
  58. CTC_EVENT_ATTNBUSY,
  59. CTC_EVENT_ATTN,
  60. CTC_EVENT_BUSY,
  61. /*
  62. * Events, representing unit-check
  63. */
  64. CTC_EVENT_UC_RCRESET,
  65. CTC_EVENT_UC_RSRESET,
  66. CTC_EVENT_UC_TXTIMEOUT,
  67. CTC_EVENT_UC_TXPARITY,
  68. CTC_EVENT_UC_HWFAIL,
  69. CTC_EVENT_UC_RXPARITY,
  70. CTC_EVENT_UC_ZERO,
  71. CTC_EVENT_UC_UNKNOWN,
  72. /*
  73. * Events, representing subchannel-check
  74. */
  75. CTC_EVENT_SC_UNKNOWN,
  76. /*
  77. * Events, representing machine checks
  78. */
  79. CTC_EVENT_MC_FAIL,
  80. CTC_EVENT_MC_GOOD,
  81. /*
  82. * Event, representing normal IRQ
  83. */
  84. CTC_EVENT_IRQ,
  85. CTC_EVENT_FINSTAT,
  86. /*
  87. * Event, representing timer expiry.
  88. */
  89. CTC_EVENT_TIMER,
  90. /*
  91. * Events, representing commands from upper levels.
  92. */
  93. CTC_EVENT_START,
  94. CTC_EVENT_STOP,
  95. CTC_NR_EVENTS,
  96. /*
  97. * additional MPC events
  98. */
  99. CTC_EVENT_SEND_XID = CTC_NR_EVENTS,
  100. CTC_EVENT_RSWEEP_TIMER,
  101. /*
  102. * MUST be always the last element!!
  103. */
  104. CTC_MPC_NR_EVENTS,
  105. };
  106. /*
  107. * States of the channel statemachine(s) for ctc and ctcmpc.
  108. */
  109. enum ctc_ch_states {
  110. /*
  111. * Channel not assigned to any device,
  112. * initial state, direction invalid
  113. */
  114. CTC_STATE_IDLE,
  115. /*
  116. * Channel assigned but not operating
  117. */
  118. CTC_STATE_STOPPED,
  119. CTC_STATE_STARTWAIT,
  120. CTC_STATE_STARTRETRY,
  121. CTC_STATE_SETUPWAIT,
  122. CTC_STATE_RXINIT,
  123. CTC_STATE_TXINIT,
  124. CTC_STATE_RX,
  125. CTC_STATE_TX,
  126. CTC_STATE_RXIDLE,
  127. CTC_STATE_TXIDLE,
  128. CTC_STATE_RXERR,
  129. CTC_STATE_TXERR,
  130. CTC_STATE_TERM,
  131. CTC_STATE_DTERM,
  132. CTC_STATE_NOTOP,
  133. CTC_NR_STATES, /* MUST be the last element of non-expanded states */
  134. /*
  135. * additional MPC states
  136. */
  137. CH_XID0_PENDING = CTC_NR_STATES,
  138. CH_XID0_INPROGRESS,
  139. CH_XID7_PENDING,
  140. CH_XID7_PENDING1,
  141. CH_XID7_PENDING2,
  142. CH_XID7_PENDING3,
  143. CH_XID7_PENDING4,
  144. CTC_MPC_NR_STATES, /* MUST be the last element of expanded mpc states */
  145. };
  146. extern const char *ctc_ch_event_names[];
  147. extern const char *ctc_ch_state_names[];
  148. void ctcm_ccw_check_rc(struct channel *ch, int rc, char *msg);
  149. void ctcm_purge_skb_queue(struct sk_buff_head *q);
  150. void fsm_action_nop(fsm_instance *fi, int event, void *arg);
  151. /*
  152. * ----- non-static actions for ctcm channel statemachine -----
  153. *
  154. */
  155. void ctcm_chx_txidle(fsm_instance *fi, int event, void *arg);
  156. /*
  157. * ----- FSM (state/event/action) of the ctcm channel statemachine -----
  158. */
  159. extern const fsm_node ch_fsm[];
  160. extern int ch_fsm_len;
  161. /*
  162. * ----- non-static actions for ctcmpc channel statemachine ----
  163. *
  164. */
  165. /* shared :
  166. void ctcm_chx_txidle(fsm_instance * fi, int event, void *arg);
  167. */
  168. void ctcmpc_chx_rxidle(fsm_instance *fi, int event, void *arg);
  169. /*
  170. * ----- FSM (state/event/action) of the ctcmpc channel statemachine -----
  171. */
  172. extern const fsm_node ctcmpc_ch_fsm[];
  173. extern int mpc_ch_fsm_len;
  174. /*
  175. * Definitions for the device interface statemachine for ctc and mpc
  176. */
  177. /*
  178. * States of the device interface statemachine.
  179. */
  180. enum dev_states {
  181. DEV_STATE_STOPPED,
  182. DEV_STATE_STARTWAIT_RXTX,
  183. DEV_STATE_STARTWAIT_RX,
  184. DEV_STATE_STARTWAIT_TX,
  185. DEV_STATE_STOPWAIT_RXTX,
  186. DEV_STATE_STOPWAIT_RX,
  187. DEV_STATE_STOPWAIT_TX,
  188. DEV_STATE_RUNNING,
  189. /*
  190. * MUST be always the last element!!
  191. */
  192. CTCM_NR_DEV_STATES
  193. };
  194. extern const char *dev_state_names[];
  195. /*
  196. * Events of the device interface statemachine.
  197. * ctcm and ctcmpc
  198. */
  199. enum dev_events {
  200. DEV_EVENT_START,
  201. DEV_EVENT_STOP,
  202. DEV_EVENT_RXUP,
  203. DEV_EVENT_TXUP,
  204. DEV_EVENT_RXDOWN,
  205. DEV_EVENT_TXDOWN,
  206. DEV_EVENT_RESTART,
  207. /*
  208. * MUST be always the last element!!
  209. */
  210. CTCM_NR_DEV_EVENTS
  211. };
  212. extern const char *dev_event_names[];
  213. /*
  214. * Actions for the device interface statemachine.
  215. * ctc and ctcmpc
  216. */
  217. /*
  218. static void dev_action_start(fsm_instance * fi, int event, void *arg);
  219. static void dev_action_stop(fsm_instance * fi, int event, void *arg);
  220. static void dev_action_restart(fsm_instance *fi, int event, void *arg);
  221. static void dev_action_chup(fsm_instance * fi, int event, void *arg);
  222. static void dev_action_chdown(fsm_instance * fi, int event, void *arg);
  223. */
  224. /*
  225. * The (state/event/action) fsm table of the device interface statemachine.
  226. * ctcm and ctcmpc
  227. */
  228. extern const fsm_node dev_fsm[];
  229. extern int dev_fsm_len;
  230. /*
  231. * Definitions for the MPC Group statemachine
  232. */
  233. /*
  234. * MPC Group Station FSM States
  235. State Name When In This State
  236. ====================== =======================================
  237. MPCG_STATE_RESET Initial State When Driver Loaded
  238. We receive and send NOTHING
  239. MPCG_STATE_INOP INOP Received.
  240. Group level non-recoverable error
  241. MPCG_STATE_READY XID exchanges for at least 1 write and
  242. 1 read channel have completed.
  243. Group is ready for data transfer.
  244. States from ctc_mpc_alloc_channel
  245. ==============================================================
  246. MPCG_STATE_XID2INITW Awaiting XID2(0) Initiation
  247. ATTN from other side will start
  248. XID negotiations.
  249. Y-side protocol only.
  250. MPCG_STATE_XID2INITX XID2(0) negotiations are in progress.
  251. At least 1, but not all, XID2(0)'s
  252. have been received from partner.
  253. MPCG_STATE_XID7INITW XID2(0) complete
  254. No XID2(7)'s have yet been received.
  255. XID2(7) negotiations pending.
  256. MPCG_STATE_XID7INITX XID2(7) negotiations in progress.
  257. At least 1, but not all, XID2(7)'s
  258. have been received from partner.
  259. MPCG_STATE_XID7INITF XID2(7) negotiations complete.
  260. Transitioning to READY.
  261. MPCG_STATE_READY Ready for Data Transfer.
  262. States from ctc_mpc_establish_connectivity call
  263. ==============================================================
  264. MPCG_STATE_XID0IOWAIT Initiating XID2(0) negotiations.
  265. X-side protocol only.
  266. ATTN-BUSY from other side will convert
  267. this to Y-side protocol and the
  268. ctc_mpc_alloc_channel flow will begin.
  269. MPCG_STATE_XID0IOWAIX XID2(0) negotiations are in progress.
  270. At least 1, but not all, XID2(0)'s
  271. have been received from partner.
  272. MPCG_STATE_XID7INITI XID2(0) complete
  273. No XID2(7)'s have yet been received.
  274. XID2(7) negotiations pending.
  275. MPCG_STATE_XID7INITZ XID2(7) negotiations in progress.
  276. At least 1, but not all, XID2(7)'s
  277. have been received from partner.
  278. MPCG_STATE_XID7INITF XID2(7) negotiations complete.
  279. Transitioning to READY.
  280. MPCG_STATE_READY Ready for Data Transfer.
  281. */
  282. enum mpcg_events {
  283. MPCG_EVENT_INOP,
  284. MPCG_EVENT_DISCONC,
  285. MPCG_EVENT_XID0DO,
  286. MPCG_EVENT_XID2,
  287. MPCG_EVENT_XID2DONE,
  288. MPCG_EVENT_XID7DONE,
  289. MPCG_EVENT_TIMER,
  290. MPCG_EVENT_DOIO,
  291. MPCG_NR_EVENTS,
  292. };
  293. enum mpcg_states {
  294. MPCG_STATE_RESET,
  295. MPCG_STATE_INOP,
  296. MPCG_STATE_XID2INITW,
  297. MPCG_STATE_XID2INITX,
  298. MPCG_STATE_XID7INITW,
  299. MPCG_STATE_XID7INITX,
  300. MPCG_STATE_XID0IOWAIT,
  301. MPCG_STATE_XID0IOWAIX,
  302. MPCG_STATE_XID7INITI,
  303. MPCG_STATE_XID7INITZ,
  304. MPCG_STATE_XID7INITF,
  305. MPCG_STATE_FLOWC,
  306. MPCG_STATE_READY,
  307. MPCG_NR_STATES,
  308. };
  309. #endif
  310. /* --- This is the END my friend --- */