ctcm_fsms.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301
  1. /*
  2. * Copyright IBM Corp. 2001, 2007
  3. * Authors: Fritz Elfert (felfert@millenux.com)
  4. * Peter Tiedemann (ptiedem@de.ibm.com)
  5. * MPC additions :
  6. * Belinda Thompson (belindat@us.ibm.com)
  7. * Andy Richter (richtera@us.ibm.com)
  8. */
  9. #undef DEBUG
  10. #undef DEBUGDATA
  11. #undef DEBUGCCW
  12. #define KMSG_COMPONENT "ctcm"
  13. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <linux/slab.h>
  18. #include <linux/errno.h>
  19. #include <linux/types.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/timer.h>
  22. #include <linux/bitops.h>
  23. #include <linux/signal.h>
  24. #include <linux/string.h>
  25. #include <linux/ip.h>
  26. #include <linux/if_arp.h>
  27. #include <linux/tcp.h>
  28. #include <linux/skbuff.h>
  29. #include <linux/ctype.h>
  30. #include <net/dst.h>
  31. #include <linux/io.h>
  32. #include <asm/ccwdev.h>
  33. #include <asm/ccwgroup.h>
  34. #include <linux/uaccess.h>
  35. #include <asm/idals.h>
  36. #include "fsm.h"
  37. #include "ctcm_dbug.h"
  38. #include "ctcm_main.h"
  39. #include "ctcm_fsms.h"
  40. const char *dev_state_names[] = {
  41. [DEV_STATE_STOPPED] = "Stopped",
  42. [DEV_STATE_STARTWAIT_RXTX] = "StartWait RXTX",
  43. [DEV_STATE_STARTWAIT_RX] = "StartWait RX",
  44. [DEV_STATE_STARTWAIT_TX] = "StartWait TX",
  45. [DEV_STATE_STOPWAIT_RXTX] = "StopWait RXTX",
  46. [DEV_STATE_STOPWAIT_RX] = "StopWait RX",
  47. [DEV_STATE_STOPWAIT_TX] = "StopWait TX",
  48. [DEV_STATE_RUNNING] = "Running",
  49. };
  50. const char *dev_event_names[] = {
  51. [DEV_EVENT_START] = "Start",
  52. [DEV_EVENT_STOP] = "Stop",
  53. [DEV_EVENT_RXUP] = "RX up",
  54. [DEV_EVENT_TXUP] = "TX up",
  55. [DEV_EVENT_RXDOWN] = "RX down",
  56. [DEV_EVENT_TXDOWN] = "TX down",
  57. [DEV_EVENT_RESTART] = "Restart",
  58. };
  59. const char *ctc_ch_event_names[] = {
  60. [CTC_EVENT_IO_SUCCESS] = "ccw_device success",
  61. [CTC_EVENT_IO_EBUSY] = "ccw_device busy",
  62. [CTC_EVENT_IO_ENODEV] = "ccw_device enodev",
  63. [CTC_EVENT_IO_UNKNOWN] = "ccw_device unknown",
  64. [CTC_EVENT_ATTNBUSY] = "Status ATTN & BUSY",
  65. [CTC_EVENT_ATTN] = "Status ATTN",
  66. [CTC_EVENT_BUSY] = "Status BUSY",
  67. [CTC_EVENT_UC_RCRESET] = "Unit check remote reset",
  68. [CTC_EVENT_UC_RSRESET] = "Unit check remote system reset",
  69. [CTC_EVENT_UC_TXTIMEOUT] = "Unit check TX timeout",
  70. [CTC_EVENT_UC_TXPARITY] = "Unit check TX parity",
  71. [CTC_EVENT_UC_HWFAIL] = "Unit check Hardware failure",
  72. [CTC_EVENT_UC_RXPARITY] = "Unit check RX parity",
  73. [CTC_EVENT_UC_ZERO] = "Unit check ZERO",
  74. [CTC_EVENT_UC_UNKNOWN] = "Unit check Unknown",
  75. [CTC_EVENT_SC_UNKNOWN] = "SubChannel check Unknown",
  76. [CTC_EVENT_MC_FAIL] = "Machine check failure",
  77. [CTC_EVENT_MC_GOOD] = "Machine check operational",
  78. [CTC_EVENT_IRQ] = "IRQ normal",
  79. [CTC_EVENT_FINSTAT] = "IRQ final",
  80. [CTC_EVENT_TIMER] = "Timer",
  81. [CTC_EVENT_START] = "Start",
  82. [CTC_EVENT_STOP] = "Stop",
  83. /*
  84. * additional MPC events
  85. */
  86. [CTC_EVENT_SEND_XID] = "XID Exchange",
  87. [CTC_EVENT_RSWEEP_TIMER] = "MPC Group Sweep Timer",
  88. };
  89. const char *ctc_ch_state_names[] = {
  90. [CTC_STATE_IDLE] = "Idle",
  91. [CTC_STATE_STOPPED] = "Stopped",
  92. [CTC_STATE_STARTWAIT] = "StartWait",
  93. [CTC_STATE_STARTRETRY] = "StartRetry",
  94. [CTC_STATE_SETUPWAIT] = "SetupWait",
  95. [CTC_STATE_RXINIT] = "RX init",
  96. [CTC_STATE_TXINIT] = "TX init",
  97. [CTC_STATE_RX] = "RX",
  98. [CTC_STATE_TX] = "TX",
  99. [CTC_STATE_RXIDLE] = "RX idle",
  100. [CTC_STATE_TXIDLE] = "TX idle",
  101. [CTC_STATE_RXERR] = "RX error",
  102. [CTC_STATE_TXERR] = "TX error",
  103. [CTC_STATE_TERM] = "Terminating",
  104. [CTC_STATE_DTERM] = "Restarting",
  105. [CTC_STATE_NOTOP] = "Not operational",
  106. /*
  107. * additional MPC states
  108. */
  109. [CH_XID0_PENDING] = "Pending XID0 Start",
  110. [CH_XID0_INPROGRESS] = "In XID0 Negotiations ",
  111. [CH_XID7_PENDING] = "Pending XID7 P1 Start",
  112. [CH_XID7_PENDING1] = "Active XID7 P1 Exchange ",
  113. [CH_XID7_PENDING2] = "Pending XID7 P2 Start ",
  114. [CH_XID7_PENDING3] = "Active XID7 P2 Exchange ",
  115. [CH_XID7_PENDING4] = "XID7 Complete - Pending READY ",
  116. };
  117. static void ctcm_action_nop(fsm_instance *fi, int event, void *arg);
  118. /*
  119. * ----- static ctcm actions for channel statemachine -----
  120. *
  121. */
  122. static void chx_txdone(fsm_instance *fi, int event, void *arg);
  123. static void chx_rx(fsm_instance *fi, int event, void *arg);
  124. static void chx_rxidle(fsm_instance *fi, int event, void *arg);
  125. static void chx_firstio(fsm_instance *fi, int event, void *arg);
  126. static void ctcm_chx_setmode(fsm_instance *fi, int event, void *arg);
  127. static void ctcm_chx_start(fsm_instance *fi, int event, void *arg);
  128. static void ctcm_chx_haltio(fsm_instance *fi, int event, void *arg);
  129. static void ctcm_chx_stopped(fsm_instance *fi, int event, void *arg);
  130. static void ctcm_chx_stop(fsm_instance *fi, int event, void *arg);
  131. static void ctcm_chx_fail(fsm_instance *fi, int event, void *arg);
  132. static void ctcm_chx_setuperr(fsm_instance *fi, int event, void *arg);
  133. static void ctcm_chx_restart(fsm_instance *fi, int event, void *arg);
  134. static void ctcm_chx_rxiniterr(fsm_instance *fi, int event, void *arg);
  135. static void ctcm_chx_rxinitfail(fsm_instance *fi, int event, void *arg);
  136. static void ctcm_chx_rxdisc(fsm_instance *fi, int event, void *arg);
  137. static void ctcm_chx_txiniterr(fsm_instance *fi, int event, void *arg);
  138. static void ctcm_chx_txretry(fsm_instance *fi, int event, void *arg);
  139. static void ctcm_chx_iofatal(fsm_instance *fi, int event, void *arg);
  140. /*
  141. * ----- static ctcmpc actions for ctcmpc channel statemachine -----
  142. *
  143. */
  144. static void ctcmpc_chx_txdone(fsm_instance *fi, int event, void *arg);
  145. static void ctcmpc_chx_rx(fsm_instance *fi, int event, void *arg);
  146. static void ctcmpc_chx_firstio(fsm_instance *fi, int event, void *arg);
  147. /* shared :
  148. static void ctcm_chx_setmode(fsm_instance *fi, int event, void *arg);
  149. static void ctcm_chx_start(fsm_instance *fi, int event, void *arg);
  150. static void ctcm_chx_haltio(fsm_instance *fi, int event, void *arg);
  151. static void ctcm_chx_stopped(fsm_instance *fi, int event, void *arg);
  152. static void ctcm_chx_stop(fsm_instance *fi, int event, void *arg);
  153. static void ctcm_chx_fail(fsm_instance *fi, int event, void *arg);
  154. static void ctcm_chx_setuperr(fsm_instance *fi, int event, void *arg);
  155. static void ctcm_chx_restart(fsm_instance *fi, int event, void *arg);
  156. static void ctcm_chx_rxiniterr(fsm_instance *fi, int event, void *arg);
  157. static void ctcm_chx_rxinitfail(fsm_instance *fi, int event, void *arg);
  158. static void ctcm_chx_rxdisc(fsm_instance *fi, int event, void *arg);
  159. static void ctcm_chx_txiniterr(fsm_instance *fi, int event, void *arg);
  160. static void ctcm_chx_txretry(fsm_instance *fi, int event, void *arg);
  161. static void ctcm_chx_iofatal(fsm_instance *fi, int event, void *arg);
  162. */
  163. static void ctcmpc_chx_attn(fsm_instance *fsm, int event, void *arg);
  164. static void ctcmpc_chx_attnbusy(fsm_instance *, int, void *);
  165. static void ctcmpc_chx_resend(fsm_instance *, int, void *);
  166. static void ctcmpc_chx_send_sweep(fsm_instance *fsm, int event, void *arg);
  167. /**
  168. * Check return code of a preceding ccw_device call, halt_IO etc...
  169. *
  170. * ch : The channel, the error belongs to.
  171. * Returns the error code (!= 0) to inspect.
  172. */
  173. void ctcm_ccw_check_rc(struct channel *ch, int rc, char *msg)
  174. {
  175. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  176. "%s(%s): %s: %04x\n",
  177. CTCM_FUNTAIL, ch->id, msg, rc);
  178. switch (rc) {
  179. case -EBUSY:
  180. pr_info("%s: The communication peer is busy\n",
  181. ch->id);
  182. fsm_event(ch->fsm, CTC_EVENT_IO_EBUSY, ch);
  183. break;
  184. case -ENODEV:
  185. pr_err("%s: The specified target device is not valid\n",
  186. ch->id);
  187. fsm_event(ch->fsm, CTC_EVENT_IO_ENODEV, ch);
  188. break;
  189. default:
  190. pr_err("An I/O operation resulted in error %04x\n",
  191. rc);
  192. fsm_event(ch->fsm, CTC_EVENT_IO_UNKNOWN, ch);
  193. }
  194. }
  195. void ctcm_purge_skb_queue(struct sk_buff_head *q)
  196. {
  197. struct sk_buff *skb;
  198. CTCM_DBF_TEXT(TRACE, CTC_DBF_DEBUG, __func__);
  199. while ((skb = skb_dequeue(q))) {
  200. atomic_dec(&skb->users);
  201. dev_kfree_skb_any(skb);
  202. }
  203. }
  204. /**
  205. * NOP action for statemachines
  206. */
  207. static void ctcm_action_nop(fsm_instance *fi, int event, void *arg)
  208. {
  209. }
  210. /*
  211. * Actions for channel - statemachines.
  212. */
  213. /**
  214. * Normal data has been send. Free the corresponding
  215. * skb (it's in io_queue), reset dev->tbusy and
  216. * revert to idle state.
  217. *
  218. * fi An instance of a channel statemachine.
  219. * event The event, just happened.
  220. * arg Generic pointer, casted from channel * upon call.
  221. */
  222. static void chx_txdone(fsm_instance *fi, int event, void *arg)
  223. {
  224. struct channel *ch = arg;
  225. struct net_device *dev = ch->netdev;
  226. struct ctcm_priv *priv = dev->ml_priv;
  227. struct sk_buff *skb;
  228. int first = 1;
  229. int i;
  230. unsigned long duration;
  231. unsigned long done_stamp = jiffies;
  232. CTCM_PR_DEBUG("%s(%s): %s\n", __func__, ch->id, dev->name);
  233. duration = done_stamp - ch->prof.send_stamp;
  234. if (duration > ch->prof.tx_time)
  235. ch->prof.tx_time = duration;
  236. if (ch->irb->scsw.cmd.count != 0)
  237. CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
  238. "%s(%s): TX not complete, remaining %d bytes",
  239. CTCM_FUNTAIL, dev->name, ch->irb->scsw.cmd.count);
  240. fsm_deltimer(&ch->timer);
  241. while ((skb = skb_dequeue(&ch->io_queue))) {
  242. priv->stats.tx_packets++;
  243. priv->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
  244. if (first) {
  245. priv->stats.tx_bytes += 2;
  246. first = 0;
  247. }
  248. atomic_dec(&skb->users);
  249. dev_kfree_skb_irq(skb);
  250. }
  251. spin_lock(&ch->collect_lock);
  252. clear_normalized_cda(&ch->ccw[4]);
  253. if (ch->collect_len > 0) {
  254. int rc;
  255. if (ctcm_checkalloc_buffer(ch)) {
  256. spin_unlock(&ch->collect_lock);
  257. return;
  258. }
  259. ch->trans_skb->data = ch->trans_skb_data;
  260. skb_reset_tail_pointer(ch->trans_skb);
  261. ch->trans_skb->len = 0;
  262. if (ch->prof.maxmulti < (ch->collect_len + 2))
  263. ch->prof.maxmulti = ch->collect_len + 2;
  264. if (ch->prof.maxcqueue < skb_queue_len(&ch->collect_queue))
  265. ch->prof.maxcqueue = skb_queue_len(&ch->collect_queue);
  266. *((__u16 *)skb_put(ch->trans_skb, 2)) = ch->collect_len + 2;
  267. i = 0;
  268. while ((skb = skb_dequeue(&ch->collect_queue))) {
  269. skb_copy_from_linear_data(skb,
  270. skb_put(ch->trans_skb, skb->len), skb->len);
  271. priv->stats.tx_packets++;
  272. priv->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
  273. atomic_dec(&skb->users);
  274. dev_kfree_skb_irq(skb);
  275. i++;
  276. }
  277. ch->collect_len = 0;
  278. spin_unlock(&ch->collect_lock);
  279. ch->ccw[1].count = ch->trans_skb->len;
  280. fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
  281. ch->prof.send_stamp = jiffies;
  282. rc = ccw_device_start(ch->cdev, &ch->ccw[0],
  283. (unsigned long)ch, 0xff, 0);
  284. ch->prof.doios_multi++;
  285. if (rc != 0) {
  286. priv->stats.tx_dropped += i;
  287. priv->stats.tx_errors += i;
  288. fsm_deltimer(&ch->timer);
  289. ctcm_ccw_check_rc(ch, rc, "chained TX");
  290. }
  291. } else {
  292. spin_unlock(&ch->collect_lock);
  293. fsm_newstate(fi, CTC_STATE_TXIDLE);
  294. }
  295. ctcm_clear_busy_do(dev);
  296. }
  297. /**
  298. * Initial data is sent.
  299. * Notify device statemachine that we are up and
  300. * running.
  301. *
  302. * fi An instance of a channel statemachine.
  303. * event The event, just happened.
  304. * arg Generic pointer, casted from channel * upon call.
  305. */
  306. void ctcm_chx_txidle(fsm_instance *fi, int event, void *arg)
  307. {
  308. struct channel *ch = arg;
  309. struct net_device *dev = ch->netdev;
  310. struct ctcm_priv *priv = dev->ml_priv;
  311. CTCM_PR_DEBUG("%s(%s): %s\n", __func__, ch->id, dev->name);
  312. fsm_deltimer(&ch->timer);
  313. fsm_newstate(fi, CTC_STATE_TXIDLE);
  314. fsm_event(priv->fsm, DEV_EVENT_TXUP, ch->netdev);
  315. }
  316. /**
  317. * Got normal data, check for sanity, queue it up, allocate new buffer
  318. * trigger bottom half, and initiate next read.
  319. *
  320. * fi An instance of a channel statemachine.
  321. * event The event, just happened.
  322. * arg Generic pointer, casted from channel * upon call.
  323. */
  324. static void chx_rx(fsm_instance *fi, int event, void *arg)
  325. {
  326. struct channel *ch = arg;
  327. struct net_device *dev = ch->netdev;
  328. struct ctcm_priv *priv = dev->ml_priv;
  329. int len = ch->max_bufsize - ch->irb->scsw.cmd.count;
  330. struct sk_buff *skb = ch->trans_skb;
  331. __u16 block_len = *((__u16 *)skb->data);
  332. int check_len;
  333. int rc;
  334. fsm_deltimer(&ch->timer);
  335. if (len < 8) {
  336. CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
  337. "%s(%s): got packet with length %d < 8\n",
  338. CTCM_FUNTAIL, dev->name, len);
  339. priv->stats.rx_dropped++;
  340. priv->stats.rx_length_errors++;
  341. goto again;
  342. }
  343. if (len > ch->max_bufsize) {
  344. CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
  345. "%s(%s): got packet with length %d > %d\n",
  346. CTCM_FUNTAIL, dev->name, len, ch->max_bufsize);
  347. priv->stats.rx_dropped++;
  348. priv->stats.rx_length_errors++;
  349. goto again;
  350. }
  351. /*
  352. * VM TCP seems to have a bug sending 2 trailing bytes of garbage.
  353. */
  354. switch (ch->protocol) {
  355. case CTCM_PROTO_S390:
  356. case CTCM_PROTO_OS390:
  357. check_len = block_len + 2;
  358. break;
  359. default:
  360. check_len = block_len;
  361. break;
  362. }
  363. if ((len < block_len) || (len > check_len)) {
  364. CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
  365. "%s(%s): got block length %d != rx length %d\n",
  366. CTCM_FUNTAIL, dev->name, block_len, len);
  367. if (do_debug)
  368. ctcmpc_dump_skb(skb, 0);
  369. *((__u16 *)skb->data) = len;
  370. priv->stats.rx_dropped++;
  371. priv->stats.rx_length_errors++;
  372. goto again;
  373. }
  374. if (block_len > 2) {
  375. *((__u16 *)skb->data) = block_len - 2;
  376. ctcm_unpack_skb(ch, skb);
  377. }
  378. again:
  379. skb->data = ch->trans_skb_data;
  380. skb_reset_tail_pointer(skb);
  381. skb->len = 0;
  382. if (ctcm_checkalloc_buffer(ch))
  383. return;
  384. ch->ccw[1].count = ch->max_bufsize;
  385. rc = ccw_device_start(ch->cdev, &ch->ccw[0],
  386. (unsigned long)ch, 0xff, 0);
  387. if (rc != 0)
  388. ctcm_ccw_check_rc(ch, rc, "normal RX");
  389. }
  390. /**
  391. * Initialize connection by sending a __u16 of value 0.
  392. *
  393. * fi An instance of a channel statemachine.
  394. * event The event, just happened.
  395. * arg Generic pointer, casted from channel * upon call.
  396. */
  397. static void chx_firstio(fsm_instance *fi, int event, void *arg)
  398. {
  399. int rc;
  400. struct channel *ch = arg;
  401. int fsmstate = fsm_getstate(fi);
  402. CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
  403. "%s(%s) : %02x",
  404. CTCM_FUNTAIL, ch->id, fsmstate);
  405. ch->sense_rc = 0; /* reset unit check report control */
  406. if (fsmstate == CTC_STATE_TXIDLE)
  407. CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
  408. "%s(%s): remote side issued READ?, init.\n",
  409. CTCM_FUNTAIL, ch->id);
  410. fsm_deltimer(&ch->timer);
  411. if (ctcm_checkalloc_buffer(ch))
  412. return;
  413. if ((fsmstate == CTC_STATE_SETUPWAIT) &&
  414. (ch->protocol == CTCM_PROTO_OS390)) {
  415. /* OS/390 resp. z/OS */
  416. if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
  417. *((__u16 *)ch->trans_skb->data) = CTCM_INITIAL_BLOCKLEN;
  418. fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC,
  419. CTC_EVENT_TIMER, ch);
  420. chx_rxidle(fi, event, arg);
  421. } else {
  422. struct net_device *dev = ch->netdev;
  423. struct ctcm_priv *priv = dev->ml_priv;
  424. fsm_newstate(fi, CTC_STATE_TXIDLE);
  425. fsm_event(priv->fsm, DEV_EVENT_TXUP, dev);
  426. }
  427. return;
  428. }
  429. /*
  430. * Don't setup a timer for receiving the initial RX frame
  431. * if in compatibility mode, since VM TCP delays the initial
  432. * frame until it has some data to send.
  433. */
  434. if ((CHANNEL_DIRECTION(ch->flags) == CTCM_WRITE) ||
  435. (ch->protocol != CTCM_PROTO_S390))
  436. fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
  437. *((__u16 *)ch->trans_skb->data) = CTCM_INITIAL_BLOCKLEN;
  438. ch->ccw[1].count = 2; /* Transfer only length */
  439. fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == CTCM_READ)
  440. ? CTC_STATE_RXINIT : CTC_STATE_TXINIT);
  441. rc = ccw_device_start(ch->cdev, &ch->ccw[0],
  442. (unsigned long)ch, 0xff, 0);
  443. if (rc != 0) {
  444. fsm_deltimer(&ch->timer);
  445. fsm_newstate(fi, CTC_STATE_SETUPWAIT);
  446. ctcm_ccw_check_rc(ch, rc, "init IO");
  447. }
  448. /*
  449. * If in compatibility mode since we don't setup a timer, we
  450. * also signal RX channel up immediately. This enables us
  451. * to send packets early which in turn usually triggers some
  452. * reply from VM TCP which brings up the RX channel to it's
  453. * final state.
  454. */
  455. if ((CHANNEL_DIRECTION(ch->flags) == CTCM_READ) &&
  456. (ch->protocol == CTCM_PROTO_S390)) {
  457. struct net_device *dev = ch->netdev;
  458. struct ctcm_priv *priv = dev->ml_priv;
  459. fsm_event(priv->fsm, DEV_EVENT_RXUP, dev);
  460. }
  461. }
  462. /**
  463. * Got initial data, check it. If OK,
  464. * notify device statemachine that we are up and
  465. * running.
  466. *
  467. * fi An instance of a channel statemachine.
  468. * event The event, just happened.
  469. * arg Generic pointer, casted from channel * upon call.
  470. */
  471. static void chx_rxidle(fsm_instance *fi, int event, void *arg)
  472. {
  473. struct channel *ch = arg;
  474. struct net_device *dev = ch->netdev;
  475. struct ctcm_priv *priv = dev->ml_priv;
  476. __u16 buflen;
  477. int rc;
  478. fsm_deltimer(&ch->timer);
  479. buflen = *((__u16 *)ch->trans_skb->data);
  480. CTCM_PR_DEBUG("%s: %s: Initial RX count = %d\n",
  481. __func__, dev->name, buflen);
  482. if (buflen >= CTCM_INITIAL_BLOCKLEN) {
  483. if (ctcm_checkalloc_buffer(ch))
  484. return;
  485. ch->ccw[1].count = ch->max_bufsize;
  486. fsm_newstate(fi, CTC_STATE_RXIDLE);
  487. rc = ccw_device_start(ch->cdev, &ch->ccw[0],
  488. (unsigned long)ch, 0xff, 0);
  489. if (rc != 0) {
  490. fsm_newstate(fi, CTC_STATE_RXINIT);
  491. ctcm_ccw_check_rc(ch, rc, "initial RX");
  492. } else
  493. fsm_event(priv->fsm, DEV_EVENT_RXUP, dev);
  494. } else {
  495. CTCM_PR_DEBUG("%s: %s: Initial RX count %d not %d\n",
  496. __func__, dev->name,
  497. buflen, CTCM_INITIAL_BLOCKLEN);
  498. chx_firstio(fi, event, arg);
  499. }
  500. }
  501. /**
  502. * Set channel into extended mode.
  503. *
  504. * fi An instance of a channel statemachine.
  505. * event The event, just happened.
  506. * arg Generic pointer, casted from channel * upon call.
  507. */
  508. static void ctcm_chx_setmode(fsm_instance *fi, int event, void *arg)
  509. {
  510. struct channel *ch = arg;
  511. int rc;
  512. unsigned long saveflags = 0;
  513. int timeout = CTCM_TIME_5_SEC;
  514. fsm_deltimer(&ch->timer);
  515. if (IS_MPC(ch)) {
  516. timeout = 1500;
  517. CTCM_PR_DEBUG("enter %s: cp=%i ch=0x%p id=%s\n",
  518. __func__, smp_processor_id(), ch, ch->id);
  519. }
  520. fsm_addtimer(&ch->timer, timeout, CTC_EVENT_TIMER, ch);
  521. fsm_newstate(fi, CTC_STATE_SETUPWAIT);
  522. CTCM_CCW_DUMP((char *)&ch->ccw[6], sizeof(struct ccw1) * 2);
  523. if (event == CTC_EVENT_TIMER) /* only for timer not yet locked */
  524. spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
  525. /* Such conditional locking is undeterministic in
  526. * static view. => ignore sparse warnings here. */
  527. rc = ccw_device_start(ch->cdev, &ch->ccw[6],
  528. (unsigned long)ch, 0xff, 0);
  529. if (event == CTC_EVENT_TIMER) /* see above comments */
  530. spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
  531. if (rc != 0) {
  532. fsm_deltimer(&ch->timer);
  533. fsm_newstate(fi, CTC_STATE_STARTWAIT);
  534. ctcm_ccw_check_rc(ch, rc, "set Mode");
  535. } else
  536. ch->retry = 0;
  537. }
  538. /**
  539. * Setup channel.
  540. *
  541. * fi An instance of a channel statemachine.
  542. * event The event, just happened.
  543. * arg Generic pointer, casted from channel * upon call.
  544. */
  545. static void ctcm_chx_start(fsm_instance *fi, int event, void *arg)
  546. {
  547. struct channel *ch = arg;
  548. unsigned long saveflags;
  549. int rc;
  550. CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s): %s",
  551. CTCM_FUNTAIL, ch->id,
  552. (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? "RX" : "TX");
  553. if (ch->trans_skb != NULL) {
  554. clear_normalized_cda(&ch->ccw[1]);
  555. dev_kfree_skb(ch->trans_skb);
  556. ch->trans_skb = NULL;
  557. }
  558. if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
  559. ch->ccw[1].cmd_code = CCW_CMD_READ;
  560. ch->ccw[1].flags = CCW_FLAG_SLI;
  561. ch->ccw[1].count = 0;
  562. } else {
  563. ch->ccw[1].cmd_code = CCW_CMD_WRITE;
  564. ch->ccw[1].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  565. ch->ccw[1].count = 0;
  566. }
  567. if (ctcm_checkalloc_buffer(ch)) {
  568. CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
  569. "%s(%s): %s trans_skb alloc delayed "
  570. "until first transfer",
  571. CTCM_FUNTAIL, ch->id,
  572. (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ?
  573. "RX" : "TX");
  574. }
  575. ch->ccw[0].cmd_code = CCW_CMD_PREPARE;
  576. ch->ccw[0].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  577. ch->ccw[0].count = 0;
  578. ch->ccw[0].cda = 0;
  579. ch->ccw[2].cmd_code = CCW_CMD_NOOP; /* jointed CE + DE */
  580. ch->ccw[2].flags = CCW_FLAG_SLI;
  581. ch->ccw[2].count = 0;
  582. ch->ccw[2].cda = 0;
  583. memcpy(&ch->ccw[3], &ch->ccw[0], sizeof(struct ccw1) * 3);
  584. ch->ccw[4].cda = 0;
  585. ch->ccw[4].flags &= ~CCW_FLAG_IDA;
  586. fsm_newstate(fi, CTC_STATE_STARTWAIT);
  587. fsm_addtimer(&ch->timer, 1000, CTC_EVENT_TIMER, ch);
  588. spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
  589. rc = ccw_device_halt(ch->cdev, (unsigned long)ch);
  590. spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
  591. if (rc != 0) {
  592. if (rc != -EBUSY)
  593. fsm_deltimer(&ch->timer);
  594. ctcm_ccw_check_rc(ch, rc, "initial HaltIO");
  595. }
  596. }
  597. /**
  598. * Shutdown a channel.
  599. *
  600. * fi An instance of a channel statemachine.
  601. * event The event, just happened.
  602. * arg Generic pointer, casted from channel * upon call.
  603. */
  604. static void ctcm_chx_haltio(fsm_instance *fi, int event, void *arg)
  605. {
  606. struct channel *ch = arg;
  607. unsigned long saveflags = 0;
  608. int rc;
  609. int oldstate;
  610. fsm_deltimer(&ch->timer);
  611. if (IS_MPC(ch))
  612. fsm_deltimer(&ch->sweep_timer);
  613. fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
  614. if (event == CTC_EVENT_STOP) /* only for STOP not yet locked */
  615. spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
  616. /* Such conditional locking is undeterministic in
  617. * static view. => ignore sparse warnings here. */
  618. oldstate = fsm_getstate(fi);
  619. fsm_newstate(fi, CTC_STATE_TERM);
  620. rc = ccw_device_halt(ch->cdev, (unsigned long)ch);
  621. if (event == CTC_EVENT_STOP)
  622. spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
  623. /* see remark above about conditional locking */
  624. if (rc != 0 && rc != -EBUSY) {
  625. fsm_deltimer(&ch->timer);
  626. if (event != CTC_EVENT_STOP) {
  627. fsm_newstate(fi, oldstate);
  628. ctcm_ccw_check_rc(ch, rc, (char *)__func__);
  629. }
  630. }
  631. }
  632. /**
  633. * Cleanup helper for chx_fail and chx_stopped
  634. * cleanup channels queue and notify interface statemachine.
  635. *
  636. * fi An instance of a channel statemachine.
  637. * state The next state (depending on caller).
  638. * ch The channel to operate on.
  639. */
  640. static void ctcm_chx_cleanup(fsm_instance *fi, int state,
  641. struct channel *ch)
  642. {
  643. struct net_device *dev = ch->netdev;
  644. struct ctcm_priv *priv = dev->ml_priv;
  645. CTCM_DBF_TEXT_(SETUP, CTC_DBF_NOTICE,
  646. "%s(%s): %s[%d]\n",
  647. CTCM_FUNTAIL, dev->name, ch->id, state);
  648. fsm_deltimer(&ch->timer);
  649. if (IS_MPC(ch))
  650. fsm_deltimer(&ch->sweep_timer);
  651. fsm_newstate(fi, state);
  652. if (state == CTC_STATE_STOPPED && ch->trans_skb != NULL) {
  653. clear_normalized_cda(&ch->ccw[1]);
  654. dev_kfree_skb_any(ch->trans_skb);
  655. ch->trans_skb = NULL;
  656. }
  657. ch->th_seg = 0x00;
  658. ch->th_seq_num = 0x00;
  659. if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
  660. skb_queue_purge(&ch->io_queue);
  661. fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
  662. } else {
  663. ctcm_purge_skb_queue(&ch->io_queue);
  664. if (IS_MPC(ch))
  665. ctcm_purge_skb_queue(&ch->sweep_queue);
  666. spin_lock(&ch->collect_lock);
  667. ctcm_purge_skb_queue(&ch->collect_queue);
  668. ch->collect_len = 0;
  669. spin_unlock(&ch->collect_lock);
  670. fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
  671. }
  672. }
  673. /**
  674. * A channel has successfully been halted.
  675. * Cleanup it's queue and notify interface statemachine.
  676. *
  677. * fi An instance of a channel statemachine.
  678. * event The event, just happened.
  679. * arg Generic pointer, casted from channel * upon call.
  680. */
  681. static void ctcm_chx_stopped(fsm_instance *fi, int event, void *arg)
  682. {
  683. ctcm_chx_cleanup(fi, CTC_STATE_STOPPED, arg);
  684. }
  685. /**
  686. * A stop command from device statemachine arrived and we are in
  687. * not operational mode. Set state to stopped.
  688. *
  689. * fi An instance of a channel statemachine.
  690. * event The event, just happened.
  691. * arg Generic pointer, casted from channel * upon call.
  692. */
  693. static void ctcm_chx_stop(fsm_instance *fi, int event, void *arg)
  694. {
  695. fsm_newstate(fi, CTC_STATE_STOPPED);
  696. }
  697. /**
  698. * A machine check for no path, not operational status or gone device has
  699. * happened.
  700. * Cleanup queue and notify interface statemachine.
  701. *
  702. * fi An instance of a channel statemachine.
  703. * event The event, just happened.
  704. * arg Generic pointer, casted from channel * upon call.
  705. */
  706. static void ctcm_chx_fail(fsm_instance *fi, int event, void *arg)
  707. {
  708. ctcm_chx_cleanup(fi, CTC_STATE_NOTOP, arg);
  709. }
  710. /**
  711. * Handle error during setup of channel.
  712. *
  713. * fi An instance of a channel statemachine.
  714. * event The event, just happened.
  715. * arg Generic pointer, casted from channel * upon call.
  716. */
  717. static void ctcm_chx_setuperr(fsm_instance *fi, int event, void *arg)
  718. {
  719. struct channel *ch = arg;
  720. struct net_device *dev = ch->netdev;
  721. struct ctcm_priv *priv = dev->ml_priv;
  722. /*
  723. * Special case: Got UC_RCRESET on setmode.
  724. * This means that remote side isn't setup. In this case
  725. * simply retry after some 10 secs...
  726. */
  727. if ((fsm_getstate(fi) == CTC_STATE_SETUPWAIT) &&
  728. ((event == CTC_EVENT_UC_RCRESET) ||
  729. (event == CTC_EVENT_UC_RSRESET))) {
  730. fsm_newstate(fi, CTC_STATE_STARTRETRY);
  731. fsm_deltimer(&ch->timer);
  732. fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
  733. if (!IS_MPC(ch) &&
  734. (CHANNEL_DIRECTION(ch->flags) == CTCM_READ)) {
  735. int rc = ccw_device_halt(ch->cdev, (unsigned long)ch);
  736. if (rc != 0)
  737. ctcm_ccw_check_rc(ch, rc,
  738. "HaltIO in chx_setuperr");
  739. }
  740. return;
  741. }
  742. CTCM_DBF_TEXT_(ERROR, CTC_DBF_CRIT,
  743. "%s(%s) : %s error during %s channel setup state=%s\n",
  744. CTCM_FUNTAIL, dev->name, ctc_ch_event_names[event],
  745. (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? "RX" : "TX",
  746. fsm_getstate_str(fi));
  747. if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
  748. fsm_newstate(fi, CTC_STATE_RXERR);
  749. fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
  750. } else {
  751. fsm_newstate(fi, CTC_STATE_TXERR);
  752. fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
  753. }
  754. }
  755. /**
  756. * Restart a channel after an error.
  757. *
  758. * fi An instance of a channel statemachine.
  759. * event The event, just happened.
  760. * arg Generic pointer, casted from channel * upon call.
  761. */
  762. static void ctcm_chx_restart(fsm_instance *fi, int event, void *arg)
  763. {
  764. struct channel *ch = arg;
  765. struct net_device *dev = ch->netdev;
  766. unsigned long saveflags = 0;
  767. int oldstate;
  768. int rc;
  769. CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
  770. "%s: %s[%d] of %s\n",
  771. CTCM_FUNTAIL, ch->id, event, dev->name);
  772. fsm_deltimer(&ch->timer);
  773. fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
  774. oldstate = fsm_getstate(fi);
  775. fsm_newstate(fi, CTC_STATE_STARTWAIT);
  776. if (event == CTC_EVENT_TIMER) /* only for timer not yet locked */
  777. spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
  778. /* Such conditional locking is a known problem for
  779. * sparse because its undeterministic in static view.
  780. * Warnings should be ignored here. */
  781. rc = ccw_device_halt(ch->cdev, (unsigned long)ch);
  782. if (event == CTC_EVENT_TIMER)
  783. spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
  784. if (rc != 0) {
  785. if (rc != -EBUSY) {
  786. fsm_deltimer(&ch->timer);
  787. fsm_newstate(fi, oldstate);
  788. }
  789. ctcm_ccw_check_rc(ch, rc, "HaltIO in ctcm_chx_restart");
  790. }
  791. }
  792. /**
  793. * Handle error during RX initial handshake (exchange of
  794. * 0-length block header)
  795. *
  796. * fi An instance of a channel statemachine.
  797. * event The event, just happened.
  798. * arg Generic pointer, casted from channel * upon call.
  799. */
  800. static void ctcm_chx_rxiniterr(fsm_instance *fi, int event, void *arg)
  801. {
  802. struct channel *ch = arg;
  803. struct net_device *dev = ch->netdev;
  804. struct ctcm_priv *priv = dev->ml_priv;
  805. if (event == CTC_EVENT_TIMER) {
  806. if (!IS_MPCDEV(dev))
  807. /* TODO : check if MPC deletes timer somewhere */
  808. fsm_deltimer(&ch->timer);
  809. if (ch->retry++ < 3)
  810. ctcm_chx_restart(fi, event, arg);
  811. else {
  812. fsm_newstate(fi, CTC_STATE_RXERR);
  813. fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
  814. }
  815. } else {
  816. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  817. "%s(%s): %s in %s", CTCM_FUNTAIL, ch->id,
  818. ctc_ch_event_names[event], fsm_getstate_str(fi));
  819. dev_warn(&dev->dev,
  820. "Initialization failed with RX/TX init handshake "
  821. "error %s\n", ctc_ch_event_names[event]);
  822. }
  823. }
  824. /**
  825. * Notify device statemachine if we gave up initialization
  826. * of RX channel.
  827. *
  828. * fi An instance of a channel statemachine.
  829. * event The event, just happened.
  830. * arg Generic pointer, casted from channel * upon call.
  831. */
  832. static void ctcm_chx_rxinitfail(fsm_instance *fi, int event, void *arg)
  833. {
  834. struct channel *ch = arg;
  835. struct net_device *dev = ch->netdev;
  836. struct ctcm_priv *priv = dev->ml_priv;
  837. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  838. "%s(%s): RX %s busy, init. fail",
  839. CTCM_FUNTAIL, dev->name, ch->id);
  840. fsm_newstate(fi, CTC_STATE_RXERR);
  841. fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
  842. }
  843. /**
  844. * Handle RX Unit check remote reset (remote disconnected)
  845. *
  846. * fi An instance of a channel statemachine.
  847. * event The event, just happened.
  848. * arg Generic pointer, casted from channel * upon call.
  849. */
  850. static void ctcm_chx_rxdisc(fsm_instance *fi, int event, void *arg)
  851. {
  852. struct channel *ch = arg;
  853. struct channel *ch2;
  854. struct net_device *dev = ch->netdev;
  855. struct ctcm_priv *priv = dev->ml_priv;
  856. CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
  857. "%s: %s: remote disconnect - re-init ...",
  858. CTCM_FUNTAIL, dev->name);
  859. fsm_deltimer(&ch->timer);
  860. /*
  861. * Notify device statemachine
  862. */
  863. fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
  864. fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
  865. fsm_newstate(fi, CTC_STATE_DTERM);
  866. ch2 = priv->channel[CTCM_WRITE];
  867. fsm_newstate(ch2->fsm, CTC_STATE_DTERM);
  868. ccw_device_halt(ch->cdev, (unsigned long)ch);
  869. ccw_device_halt(ch2->cdev, (unsigned long)ch2);
  870. }
  871. /**
  872. * Handle error during TX channel initialization.
  873. *
  874. * fi An instance of a channel statemachine.
  875. * event The event, just happened.
  876. * arg Generic pointer, casted from channel * upon call.
  877. */
  878. static void ctcm_chx_txiniterr(fsm_instance *fi, int event, void *arg)
  879. {
  880. struct channel *ch = arg;
  881. struct net_device *dev = ch->netdev;
  882. struct ctcm_priv *priv = dev->ml_priv;
  883. if (event == CTC_EVENT_TIMER) {
  884. fsm_deltimer(&ch->timer);
  885. if (ch->retry++ < 3)
  886. ctcm_chx_restart(fi, event, arg);
  887. else {
  888. fsm_newstate(fi, CTC_STATE_TXERR);
  889. fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
  890. }
  891. } else {
  892. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  893. "%s(%s): %s in %s", CTCM_FUNTAIL, ch->id,
  894. ctc_ch_event_names[event], fsm_getstate_str(fi));
  895. dev_warn(&dev->dev,
  896. "Initialization failed with RX/TX init handshake "
  897. "error %s\n", ctc_ch_event_names[event]);
  898. }
  899. }
  900. /**
  901. * Handle TX timeout by retrying operation.
  902. *
  903. * fi An instance of a channel statemachine.
  904. * event The event, just happened.
  905. * arg Generic pointer, casted from channel * upon call.
  906. */
  907. static void ctcm_chx_txretry(fsm_instance *fi, int event, void *arg)
  908. {
  909. struct channel *ch = arg;
  910. struct net_device *dev = ch->netdev;
  911. struct ctcm_priv *priv = dev->ml_priv;
  912. struct sk_buff *skb;
  913. CTCM_PR_DEBUG("Enter: %s: cp=%i ch=0x%p id=%s\n",
  914. __func__, smp_processor_id(), ch, ch->id);
  915. fsm_deltimer(&ch->timer);
  916. if (ch->retry++ > 3) {
  917. struct mpc_group *gptr = priv->mpcg;
  918. CTCM_DBF_TEXT_(TRACE, CTC_DBF_INFO,
  919. "%s: %s: retries exceeded",
  920. CTCM_FUNTAIL, ch->id);
  921. fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
  922. /* call restart if not MPC or if MPC and mpcg fsm is ready.
  923. use gptr as mpc indicator */
  924. if (!(gptr && (fsm_getstate(gptr->fsm) != MPCG_STATE_READY)))
  925. ctcm_chx_restart(fi, event, arg);
  926. goto done;
  927. }
  928. CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
  929. "%s : %s: retry %d",
  930. CTCM_FUNTAIL, ch->id, ch->retry);
  931. skb = skb_peek(&ch->io_queue);
  932. if (skb) {
  933. int rc = 0;
  934. unsigned long saveflags = 0;
  935. clear_normalized_cda(&ch->ccw[4]);
  936. ch->ccw[4].count = skb->len;
  937. if (set_normalized_cda(&ch->ccw[4], skb->data)) {
  938. CTCM_DBF_TEXT_(TRACE, CTC_DBF_INFO,
  939. "%s: %s: IDAL alloc failed",
  940. CTCM_FUNTAIL, ch->id);
  941. fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
  942. ctcm_chx_restart(fi, event, arg);
  943. goto done;
  944. }
  945. fsm_addtimer(&ch->timer, 1000, CTC_EVENT_TIMER, ch);
  946. if (event == CTC_EVENT_TIMER) /* for TIMER not yet locked */
  947. spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
  948. /* Such conditional locking is a known problem for
  949. * sparse because its undeterministic in static view.
  950. * Warnings should be ignored here. */
  951. if (do_debug_ccw)
  952. ctcmpc_dumpit((char *)&ch->ccw[3],
  953. sizeof(struct ccw1) * 3);
  954. rc = ccw_device_start(ch->cdev, &ch->ccw[3],
  955. (unsigned long)ch, 0xff, 0);
  956. if (event == CTC_EVENT_TIMER)
  957. spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev),
  958. saveflags);
  959. if (rc != 0) {
  960. fsm_deltimer(&ch->timer);
  961. ctcm_ccw_check_rc(ch, rc, "TX in chx_txretry");
  962. ctcm_purge_skb_queue(&ch->io_queue);
  963. }
  964. }
  965. done:
  966. return;
  967. }
  968. /**
  969. * Handle fatal errors during an I/O command.
  970. *
  971. * fi An instance of a channel statemachine.
  972. * event The event, just happened.
  973. * arg Generic pointer, casted from channel * upon call.
  974. */
  975. static void ctcm_chx_iofatal(fsm_instance *fi, int event, void *arg)
  976. {
  977. struct channel *ch = arg;
  978. struct net_device *dev = ch->netdev;
  979. struct ctcm_priv *priv = dev->ml_priv;
  980. int rd = CHANNEL_DIRECTION(ch->flags);
  981. fsm_deltimer(&ch->timer);
  982. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  983. "%s: %s: %s unrecoverable channel error",
  984. CTCM_FUNTAIL, ch->id, rd == CTCM_READ ? "RX" : "TX");
  985. if (IS_MPC(ch)) {
  986. priv->stats.tx_dropped++;
  987. priv->stats.tx_errors++;
  988. }
  989. if (rd == CTCM_READ) {
  990. fsm_newstate(fi, CTC_STATE_RXERR);
  991. fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
  992. } else {
  993. fsm_newstate(fi, CTC_STATE_TXERR);
  994. fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
  995. }
  996. }
  997. /*
  998. * The ctcm statemachine for a channel.
  999. */
  1000. const fsm_node ch_fsm[] = {
  1001. { CTC_STATE_STOPPED, CTC_EVENT_STOP, ctcm_action_nop },
  1002. { CTC_STATE_STOPPED, CTC_EVENT_START, ctcm_chx_start },
  1003. { CTC_STATE_STOPPED, CTC_EVENT_FINSTAT, ctcm_action_nop },
  1004. { CTC_STATE_STOPPED, CTC_EVENT_MC_FAIL, ctcm_action_nop },
  1005. { CTC_STATE_NOTOP, CTC_EVENT_STOP, ctcm_chx_stop },
  1006. { CTC_STATE_NOTOP, CTC_EVENT_START, ctcm_action_nop },
  1007. { CTC_STATE_NOTOP, CTC_EVENT_FINSTAT, ctcm_action_nop },
  1008. { CTC_STATE_NOTOP, CTC_EVENT_MC_FAIL, ctcm_action_nop },
  1009. { CTC_STATE_NOTOP, CTC_EVENT_MC_GOOD, ctcm_chx_start },
  1010. { CTC_STATE_STARTWAIT, CTC_EVENT_STOP, ctcm_chx_haltio },
  1011. { CTC_STATE_STARTWAIT, CTC_EVENT_START, ctcm_action_nop },
  1012. { CTC_STATE_STARTWAIT, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
  1013. { CTC_STATE_STARTWAIT, CTC_EVENT_TIMER, ctcm_chx_setuperr },
  1014. { CTC_STATE_STARTWAIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1015. { CTC_STATE_STARTWAIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1016. { CTC_STATE_STARTRETRY, CTC_EVENT_STOP, ctcm_chx_haltio },
  1017. { CTC_STATE_STARTRETRY, CTC_EVENT_TIMER, ctcm_chx_setmode },
  1018. { CTC_STATE_STARTRETRY, CTC_EVENT_FINSTAT, ctcm_action_nop },
  1019. { CTC_STATE_STARTRETRY, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1020. { CTC_STATE_SETUPWAIT, CTC_EVENT_STOP, ctcm_chx_haltio },
  1021. { CTC_STATE_SETUPWAIT, CTC_EVENT_START, ctcm_action_nop },
  1022. { CTC_STATE_SETUPWAIT, CTC_EVENT_FINSTAT, chx_firstio },
  1023. { CTC_STATE_SETUPWAIT, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
  1024. { CTC_STATE_SETUPWAIT, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
  1025. { CTC_STATE_SETUPWAIT, CTC_EVENT_TIMER, ctcm_chx_setmode },
  1026. { CTC_STATE_SETUPWAIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1027. { CTC_STATE_SETUPWAIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1028. { CTC_STATE_RXINIT, CTC_EVENT_STOP, ctcm_chx_haltio },
  1029. { CTC_STATE_RXINIT, CTC_EVENT_START, ctcm_action_nop },
  1030. { CTC_STATE_RXINIT, CTC_EVENT_FINSTAT, chx_rxidle },
  1031. { CTC_STATE_RXINIT, CTC_EVENT_UC_RCRESET, ctcm_chx_rxiniterr },
  1032. { CTC_STATE_RXINIT, CTC_EVENT_UC_RSRESET, ctcm_chx_rxiniterr },
  1033. { CTC_STATE_RXINIT, CTC_EVENT_TIMER, ctcm_chx_rxiniterr },
  1034. { CTC_STATE_RXINIT, CTC_EVENT_ATTNBUSY, ctcm_chx_rxinitfail },
  1035. { CTC_STATE_RXINIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1036. { CTC_STATE_RXINIT, CTC_EVENT_UC_ZERO, chx_firstio },
  1037. { CTC_STATE_RXINIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1038. { CTC_STATE_RXIDLE, CTC_EVENT_STOP, ctcm_chx_haltio },
  1039. { CTC_STATE_RXIDLE, CTC_EVENT_START, ctcm_action_nop },
  1040. { CTC_STATE_RXIDLE, CTC_EVENT_FINSTAT, chx_rx },
  1041. { CTC_STATE_RXIDLE, CTC_EVENT_UC_RCRESET, ctcm_chx_rxdisc },
  1042. { CTC_STATE_RXIDLE, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1043. { CTC_STATE_RXIDLE, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1044. { CTC_STATE_RXIDLE, CTC_EVENT_UC_ZERO, chx_rx },
  1045. { CTC_STATE_TXINIT, CTC_EVENT_STOP, ctcm_chx_haltio },
  1046. { CTC_STATE_TXINIT, CTC_EVENT_START, ctcm_action_nop },
  1047. { CTC_STATE_TXINIT, CTC_EVENT_FINSTAT, ctcm_chx_txidle },
  1048. { CTC_STATE_TXINIT, CTC_EVENT_UC_RCRESET, ctcm_chx_txiniterr },
  1049. { CTC_STATE_TXINIT, CTC_EVENT_UC_RSRESET, ctcm_chx_txiniterr },
  1050. { CTC_STATE_TXINIT, CTC_EVENT_TIMER, ctcm_chx_txiniterr },
  1051. { CTC_STATE_TXINIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1052. { CTC_STATE_TXINIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1053. { CTC_STATE_TXIDLE, CTC_EVENT_STOP, ctcm_chx_haltio },
  1054. { CTC_STATE_TXIDLE, CTC_EVENT_START, ctcm_action_nop },
  1055. { CTC_STATE_TXIDLE, CTC_EVENT_FINSTAT, chx_firstio },
  1056. { CTC_STATE_TXIDLE, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
  1057. { CTC_STATE_TXIDLE, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
  1058. { CTC_STATE_TXIDLE, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1059. { CTC_STATE_TXIDLE, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1060. { CTC_STATE_TERM, CTC_EVENT_STOP, ctcm_action_nop },
  1061. { CTC_STATE_TERM, CTC_EVENT_START, ctcm_chx_restart },
  1062. { CTC_STATE_TERM, CTC_EVENT_FINSTAT, ctcm_chx_stopped },
  1063. { CTC_STATE_TERM, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
  1064. { CTC_STATE_TERM, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
  1065. { CTC_STATE_TERM, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1066. { CTC_STATE_DTERM, CTC_EVENT_STOP, ctcm_chx_haltio },
  1067. { CTC_STATE_DTERM, CTC_EVENT_START, ctcm_chx_restart },
  1068. { CTC_STATE_DTERM, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
  1069. { CTC_STATE_DTERM, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
  1070. { CTC_STATE_DTERM, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
  1071. { CTC_STATE_DTERM, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1072. { CTC_STATE_TX, CTC_EVENT_STOP, ctcm_chx_haltio },
  1073. { CTC_STATE_TX, CTC_EVENT_START, ctcm_action_nop },
  1074. { CTC_STATE_TX, CTC_EVENT_FINSTAT, chx_txdone },
  1075. { CTC_STATE_TX, CTC_EVENT_UC_RCRESET, ctcm_chx_txretry },
  1076. { CTC_STATE_TX, CTC_EVENT_UC_RSRESET, ctcm_chx_txretry },
  1077. { CTC_STATE_TX, CTC_EVENT_TIMER, ctcm_chx_txretry },
  1078. { CTC_STATE_TX, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1079. { CTC_STATE_TX, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1080. { CTC_STATE_RXERR, CTC_EVENT_STOP, ctcm_chx_haltio },
  1081. { CTC_STATE_TXERR, CTC_EVENT_STOP, ctcm_chx_haltio },
  1082. { CTC_STATE_TXERR, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1083. { CTC_STATE_RXERR, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1084. };
  1085. int ch_fsm_len = ARRAY_SIZE(ch_fsm);
  1086. /*
  1087. * MPC actions for mpc channel statemachine
  1088. * handling of MPC protocol requires extra
  1089. * statemachine and actions which are prefixed ctcmpc_ .
  1090. * The ctc_ch_states and ctc_ch_state_names,
  1091. * ctc_ch_events and ctc_ch_event_names share the ctcm definitions
  1092. * which are expanded by some elements.
  1093. */
  1094. /*
  1095. * Actions for mpc channel statemachine.
  1096. */
  1097. /**
  1098. * Normal data has been send. Free the corresponding
  1099. * skb (it's in io_queue), reset dev->tbusy and
  1100. * revert to idle state.
  1101. *
  1102. * fi An instance of a channel statemachine.
  1103. * event The event, just happened.
  1104. * arg Generic pointer, casted from channel * upon call.
  1105. */
  1106. static void ctcmpc_chx_txdone(fsm_instance *fi, int event, void *arg)
  1107. {
  1108. struct channel *ch = arg;
  1109. struct net_device *dev = ch->netdev;
  1110. struct ctcm_priv *priv = dev->ml_priv;
  1111. struct mpc_group *grp = priv->mpcg;
  1112. struct sk_buff *skb;
  1113. int first = 1;
  1114. int i;
  1115. __u32 data_space;
  1116. unsigned long duration;
  1117. struct sk_buff *peekskb;
  1118. int rc;
  1119. struct th_header *header;
  1120. struct pdu *p_header;
  1121. unsigned long done_stamp = jiffies;
  1122. CTCM_PR_DEBUG("Enter %s: %s cp:%i\n",
  1123. __func__, dev->name, smp_processor_id());
  1124. duration = done_stamp - ch->prof.send_stamp;
  1125. if (duration > ch->prof.tx_time)
  1126. ch->prof.tx_time = duration;
  1127. if (ch->irb->scsw.cmd.count != 0)
  1128. CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
  1129. "%s(%s): TX not complete, remaining %d bytes",
  1130. CTCM_FUNTAIL, dev->name, ch->irb->scsw.cmd.count);
  1131. fsm_deltimer(&ch->timer);
  1132. while ((skb = skb_dequeue(&ch->io_queue))) {
  1133. priv->stats.tx_packets++;
  1134. priv->stats.tx_bytes += skb->len - TH_HEADER_LENGTH;
  1135. if (first) {
  1136. priv->stats.tx_bytes += 2;
  1137. first = 0;
  1138. }
  1139. atomic_dec(&skb->users);
  1140. dev_kfree_skb_irq(skb);
  1141. }
  1142. spin_lock(&ch->collect_lock);
  1143. clear_normalized_cda(&ch->ccw[4]);
  1144. if ((ch->collect_len <= 0) || (grp->in_sweep != 0)) {
  1145. spin_unlock(&ch->collect_lock);
  1146. fsm_newstate(fi, CTC_STATE_TXIDLE);
  1147. goto done;
  1148. }
  1149. if (ctcm_checkalloc_buffer(ch)) {
  1150. spin_unlock(&ch->collect_lock);
  1151. goto done;
  1152. }
  1153. ch->trans_skb->data = ch->trans_skb_data;
  1154. skb_reset_tail_pointer(ch->trans_skb);
  1155. ch->trans_skb->len = 0;
  1156. if (ch->prof.maxmulti < (ch->collect_len + TH_HEADER_LENGTH))
  1157. ch->prof.maxmulti = ch->collect_len + TH_HEADER_LENGTH;
  1158. if (ch->prof.maxcqueue < skb_queue_len(&ch->collect_queue))
  1159. ch->prof.maxcqueue = skb_queue_len(&ch->collect_queue);
  1160. i = 0;
  1161. p_header = NULL;
  1162. data_space = grp->group_max_buflen - TH_HEADER_LENGTH;
  1163. CTCM_PR_DBGDATA("%s: building trans_skb from collect_q"
  1164. " data_space:%04x\n",
  1165. __func__, data_space);
  1166. while ((skb = skb_dequeue(&ch->collect_queue))) {
  1167. memcpy(skb_put(ch->trans_skb, skb->len), skb->data, skb->len);
  1168. p_header = (struct pdu *)
  1169. (skb_tail_pointer(ch->trans_skb) - skb->len);
  1170. p_header->pdu_flag = 0x00;
  1171. if (skb->protocol == ntohs(ETH_P_SNAP))
  1172. p_header->pdu_flag |= 0x60;
  1173. else
  1174. p_header->pdu_flag |= 0x20;
  1175. CTCM_PR_DBGDATA("%s: trans_skb len:%04x \n",
  1176. __func__, ch->trans_skb->len);
  1177. CTCM_PR_DBGDATA("%s: pdu header and data for up"
  1178. " to 32 bytes sent to vtam\n", __func__);
  1179. CTCM_D3_DUMP((char *)p_header, min_t(int, skb->len, 32));
  1180. ch->collect_len -= skb->len;
  1181. data_space -= skb->len;
  1182. priv->stats.tx_packets++;
  1183. priv->stats.tx_bytes += skb->len;
  1184. atomic_dec(&skb->users);
  1185. dev_kfree_skb_any(skb);
  1186. peekskb = skb_peek(&ch->collect_queue);
  1187. if (peekskb->len > data_space)
  1188. break;
  1189. i++;
  1190. }
  1191. /* p_header points to the last one we handled */
  1192. if (p_header)
  1193. p_header->pdu_flag |= PDU_LAST; /*Say it's the last one*/
  1194. header = kzalloc(TH_HEADER_LENGTH, gfp_type());
  1195. if (!header) {
  1196. spin_unlock(&ch->collect_lock);
  1197. fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
  1198. goto done;
  1199. }
  1200. header->th_ch_flag = TH_HAS_PDU; /* Normal data */
  1201. ch->th_seq_num++;
  1202. header->th_seq_num = ch->th_seq_num;
  1203. CTCM_PR_DBGDATA("%s: ToVTAM_th_seq= %08x\n" ,
  1204. __func__, ch->th_seq_num);
  1205. memcpy(skb_push(ch->trans_skb, TH_HEADER_LENGTH), header,
  1206. TH_HEADER_LENGTH); /* put the TH on the packet */
  1207. kfree(header);
  1208. CTCM_PR_DBGDATA("%s: trans_skb len:%04x \n",
  1209. __func__, ch->trans_skb->len);
  1210. CTCM_PR_DBGDATA("%s: up-to-50 bytes of trans_skb "
  1211. "data to vtam from collect_q\n", __func__);
  1212. CTCM_D3_DUMP((char *)ch->trans_skb->data,
  1213. min_t(int, ch->trans_skb->len, 50));
  1214. spin_unlock(&ch->collect_lock);
  1215. clear_normalized_cda(&ch->ccw[1]);
  1216. CTCM_PR_DBGDATA("ccwcda=0x%p data=0x%p\n",
  1217. (void *)(unsigned long)ch->ccw[1].cda,
  1218. ch->trans_skb->data);
  1219. ch->ccw[1].count = ch->max_bufsize;
  1220. if (set_normalized_cda(&ch->ccw[1], ch->trans_skb->data)) {
  1221. dev_kfree_skb_any(ch->trans_skb);
  1222. ch->trans_skb = NULL;
  1223. CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR,
  1224. "%s: %s: IDAL alloc failed",
  1225. CTCM_FUNTAIL, ch->id);
  1226. fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
  1227. return;
  1228. }
  1229. CTCM_PR_DBGDATA("ccwcda=0x%p data=0x%p\n",
  1230. (void *)(unsigned long)ch->ccw[1].cda,
  1231. ch->trans_skb->data);
  1232. ch->ccw[1].count = ch->trans_skb->len;
  1233. fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
  1234. ch->prof.send_stamp = jiffies;
  1235. if (do_debug_ccw)
  1236. ctcmpc_dumpit((char *)&ch->ccw[0], sizeof(struct ccw1) * 3);
  1237. rc = ccw_device_start(ch->cdev, &ch->ccw[0],
  1238. (unsigned long)ch, 0xff, 0);
  1239. ch->prof.doios_multi++;
  1240. if (rc != 0) {
  1241. priv->stats.tx_dropped += i;
  1242. priv->stats.tx_errors += i;
  1243. fsm_deltimer(&ch->timer);
  1244. ctcm_ccw_check_rc(ch, rc, "chained TX");
  1245. }
  1246. done:
  1247. ctcm_clear_busy(dev);
  1248. return;
  1249. }
  1250. /**
  1251. * Got normal data, check for sanity, queue it up, allocate new buffer
  1252. * trigger bottom half, and initiate next read.
  1253. *
  1254. * fi An instance of a channel statemachine.
  1255. * event The event, just happened.
  1256. * arg Generic pointer, casted from channel * upon call.
  1257. */
  1258. static void ctcmpc_chx_rx(fsm_instance *fi, int event, void *arg)
  1259. {
  1260. struct channel *ch = arg;
  1261. struct net_device *dev = ch->netdev;
  1262. struct ctcm_priv *priv = dev->ml_priv;
  1263. struct mpc_group *grp = priv->mpcg;
  1264. struct sk_buff *skb = ch->trans_skb;
  1265. struct sk_buff *new_skb;
  1266. unsigned long saveflags = 0; /* avoids compiler warning */
  1267. int len = ch->max_bufsize - ch->irb->scsw.cmd.count;
  1268. CTCM_PR_DEBUG("%s: %s: cp:%i %s maxbuf : %04x, len: %04x\n",
  1269. CTCM_FUNTAIL, dev->name, smp_processor_id(),
  1270. ch->id, ch->max_bufsize, len);
  1271. fsm_deltimer(&ch->timer);
  1272. if (skb == NULL) {
  1273. CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
  1274. "%s(%s): TRANS_SKB = NULL",
  1275. CTCM_FUNTAIL, dev->name);
  1276. goto again;
  1277. }
  1278. if (len < TH_HEADER_LENGTH) {
  1279. CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
  1280. "%s(%s): packet length %d to short",
  1281. CTCM_FUNTAIL, dev->name, len);
  1282. priv->stats.rx_dropped++;
  1283. priv->stats.rx_length_errors++;
  1284. } else {
  1285. /* must have valid th header or game over */
  1286. __u32 block_len = len;
  1287. len = TH_HEADER_LENGTH + XID2_LENGTH + 4;
  1288. new_skb = __dev_alloc_skb(ch->max_bufsize, GFP_ATOMIC);
  1289. if (new_skb == NULL) {
  1290. CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
  1291. "%s(%d): skb allocation failed",
  1292. CTCM_FUNTAIL, dev->name);
  1293. fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
  1294. goto again;
  1295. }
  1296. switch (fsm_getstate(grp->fsm)) {
  1297. case MPCG_STATE_RESET:
  1298. case MPCG_STATE_INOP:
  1299. dev_kfree_skb_any(new_skb);
  1300. break;
  1301. case MPCG_STATE_FLOWC:
  1302. case MPCG_STATE_READY:
  1303. memcpy(skb_put(new_skb, block_len),
  1304. skb->data, block_len);
  1305. skb_queue_tail(&ch->io_queue, new_skb);
  1306. tasklet_schedule(&ch->ch_tasklet);
  1307. break;
  1308. default:
  1309. memcpy(skb_put(new_skb, len), skb->data, len);
  1310. skb_queue_tail(&ch->io_queue, new_skb);
  1311. tasklet_hi_schedule(&ch->ch_tasklet);
  1312. break;
  1313. }
  1314. }
  1315. again:
  1316. switch (fsm_getstate(grp->fsm)) {
  1317. int rc, dolock;
  1318. case MPCG_STATE_FLOWC:
  1319. case MPCG_STATE_READY:
  1320. if (ctcm_checkalloc_buffer(ch))
  1321. break;
  1322. ch->trans_skb->data = ch->trans_skb_data;
  1323. skb_reset_tail_pointer(ch->trans_skb);
  1324. ch->trans_skb->len = 0;
  1325. ch->ccw[1].count = ch->max_bufsize;
  1326. if (do_debug_ccw)
  1327. ctcmpc_dumpit((char *)&ch->ccw[0],
  1328. sizeof(struct ccw1) * 3);
  1329. dolock = !in_irq();
  1330. if (dolock)
  1331. spin_lock_irqsave(
  1332. get_ccwdev_lock(ch->cdev), saveflags);
  1333. rc = ccw_device_start(ch->cdev, &ch->ccw[0],
  1334. (unsigned long)ch, 0xff, 0);
  1335. if (dolock) /* see remark about conditional locking */
  1336. spin_unlock_irqrestore(
  1337. get_ccwdev_lock(ch->cdev), saveflags);
  1338. if (rc != 0)
  1339. ctcm_ccw_check_rc(ch, rc, "normal RX");
  1340. default:
  1341. break;
  1342. }
  1343. CTCM_PR_DEBUG("Exit %s: %s, ch=0x%p, id=%s\n",
  1344. __func__, dev->name, ch, ch->id);
  1345. }
  1346. /**
  1347. * Initialize connection by sending a __u16 of value 0.
  1348. *
  1349. * fi An instance of a channel statemachine.
  1350. * event The event, just happened.
  1351. * arg Generic pointer, casted from channel * upon call.
  1352. */
  1353. static void ctcmpc_chx_firstio(fsm_instance *fi, int event, void *arg)
  1354. {
  1355. struct channel *ch = arg;
  1356. struct net_device *dev = ch->netdev;
  1357. struct ctcm_priv *priv = dev->ml_priv;
  1358. struct mpc_group *gptr = priv->mpcg;
  1359. CTCM_PR_DEBUG("Enter %s: id=%s, ch=0x%p\n",
  1360. __func__, ch->id, ch);
  1361. CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_INFO,
  1362. "%s: %s: chstate:%i, grpstate:%i, prot:%i\n",
  1363. CTCM_FUNTAIL, ch->id, fsm_getstate(fi),
  1364. fsm_getstate(gptr->fsm), ch->protocol);
  1365. if (fsm_getstate(fi) == CTC_STATE_TXIDLE)
  1366. MPC_DBF_DEV_NAME(TRACE, dev, "remote side issued READ? ");
  1367. fsm_deltimer(&ch->timer);
  1368. if (ctcm_checkalloc_buffer(ch))
  1369. goto done;
  1370. switch (fsm_getstate(fi)) {
  1371. case CTC_STATE_STARTRETRY:
  1372. case CTC_STATE_SETUPWAIT:
  1373. if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
  1374. ctcmpc_chx_rxidle(fi, event, arg);
  1375. } else {
  1376. fsm_newstate(fi, CTC_STATE_TXIDLE);
  1377. fsm_event(priv->fsm, DEV_EVENT_TXUP, dev);
  1378. }
  1379. goto done;
  1380. default:
  1381. break;
  1382. }
  1383. fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == CTCM_READ)
  1384. ? CTC_STATE_RXINIT : CTC_STATE_TXINIT);
  1385. done:
  1386. CTCM_PR_DEBUG("Exit %s: id=%s, ch=0x%p\n",
  1387. __func__, ch->id, ch);
  1388. return;
  1389. }
  1390. /**
  1391. * Got initial data, check it. If OK,
  1392. * notify device statemachine that we are up and
  1393. * running.
  1394. *
  1395. * fi An instance of a channel statemachine.
  1396. * event The event, just happened.
  1397. * arg Generic pointer, casted from channel * upon call.
  1398. */
  1399. void ctcmpc_chx_rxidle(fsm_instance *fi, int event, void *arg)
  1400. {
  1401. struct channel *ch = arg;
  1402. struct net_device *dev = ch->netdev;
  1403. struct ctcm_priv *priv = dev->ml_priv;
  1404. struct mpc_group *grp = priv->mpcg;
  1405. int rc;
  1406. unsigned long saveflags = 0; /* avoids compiler warning */
  1407. fsm_deltimer(&ch->timer);
  1408. CTCM_PR_DEBUG("%s: %s: %s: cp:%i, chstate:%i grpstate:%i\n",
  1409. __func__, ch->id, dev->name, smp_processor_id(),
  1410. fsm_getstate(fi), fsm_getstate(grp->fsm));
  1411. fsm_newstate(fi, CTC_STATE_RXIDLE);
  1412. /* XID processing complete */
  1413. switch (fsm_getstate(grp->fsm)) {
  1414. case MPCG_STATE_FLOWC:
  1415. case MPCG_STATE_READY:
  1416. if (ctcm_checkalloc_buffer(ch))
  1417. goto done;
  1418. ch->trans_skb->data = ch->trans_skb_data;
  1419. skb_reset_tail_pointer(ch->trans_skb);
  1420. ch->trans_skb->len = 0;
  1421. ch->ccw[1].count = ch->max_bufsize;
  1422. CTCM_CCW_DUMP((char *)&ch->ccw[0], sizeof(struct ccw1) * 3);
  1423. if (event == CTC_EVENT_START)
  1424. /* see remark about conditional locking */
  1425. spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
  1426. rc = ccw_device_start(ch->cdev, &ch->ccw[0],
  1427. (unsigned long)ch, 0xff, 0);
  1428. if (event == CTC_EVENT_START)
  1429. spin_unlock_irqrestore(
  1430. get_ccwdev_lock(ch->cdev), saveflags);
  1431. if (rc != 0) {
  1432. fsm_newstate(fi, CTC_STATE_RXINIT);
  1433. ctcm_ccw_check_rc(ch, rc, "initial RX");
  1434. goto done;
  1435. }
  1436. break;
  1437. default:
  1438. break;
  1439. }
  1440. fsm_event(priv->fsm, DEV_EVENT_RXUP, dev);
  1441. done:
  1442. return;
  1443. }
  1444. /*
  1445. * ctcmpc channel FSM action
  1446. * called from several points in ctcmpc_ch_fsm
  1447. * ctcmpc only
  1448. */
  1449. static void ctcmpc_chx_attn(fsm_instance *fsm, int event, void *arg)
  1450. {
  1451. struct channel *ch = arg;
  1452. struct net_device *dev = ch->netdev;
  1453. struct ctcm_priv *priv = dev->ml_priv;
  1454. struct mpc_group *grp = priv->mpcg;
  1455. CTCM_PR_DEBUG("%s(%s): %s(ch=0x%p), cp=%i, ChStat:%s, GrpStat:%s\n",
  1456. __func__, dev->name, ch->id, ch, smp_processor_id(),
  1457. fsm_getstate_str(ch->fsm), fsm_getstate_str(grp->fsm));
  1458. switch (fsm_getstate(grp->fsm)) {
  1459. case MPCG_STATE_XID2INITW:
  1460. /* ok..start yside xid exchanges */
  1461. if (!ch->in_mpcgroup)
  1462. break;
  1463. if (fsm_getstate(ch->fsm) == CH_XID0_PENDING) {
  1464. fsm_deltimer(&grp->timer);
  1465. fsm_addtimer(&grp->timer,
  1466. MPC_XID_TIMEOUT_VALUE,
  1467. MPCG_EVENT_TIMER, dev);
  1468. fsm_event(grp->fsm, MPCG_EVENT_XID0DO, ch);
  1469. } else if (fsm_getstate(ch->fsm) < CH_XID7_PENDING1)
  1470. /* attn rcvd before xid0 processed via bh */
  1471. fsm_newstate(ch->fsm, CH_XID7_PENDING1);
  1472. break;
  1473. case MPCG_STATE_XID2INITX:
  1474. case MPCG_STATE_XID0IOWAIT:
  1475. case MPCG_STATE_XID0IOWAIX:
  1476. /* attn rcvd before xid0 processed on ch
  1477. but mid-xid0 processing for group */
  1478. if (fsm_getstate(ch->fsm) < CH_XID7_PENDING1)
  1479. fsm_newstate(ch->fsm, CH_XID7_PENDING1);
  1480. break;
  1481. case MPCG_STATE_XID7INITW:
  1482. case MPCG_STATE_XID7INITX:
  1483. case MPCG_STATE_XID7INITI:
  1484. case MPCG_STATE_XID7INITZ:
  1485. switch (fsm_getstate(ch->fsm)) {
  1486. case CH_XID7_PENDING:
  1487. fsm_newstate(ch->fsm, CH_XID7_PENDING1);
  1488. break;
  1489. case CH_XID7_PENDING2:
  1490. fsm_newstate(ch->fsm, CH_XID7_PENDING3);
  1491. break;
  1492. }
  1493. fsm_event(grp->fsm, MPCG_EVENT_XID7DONE, dev);
  1494. break;
  1495. }
  1496. return;
  1497. }
  1498. /*
  1499. * ctcmpc channel FSM action
  1500. * called from one point in ctcmpc_ch_fsm
  1501. * ctcmpc only
  1502. */
  1503. static void ctcmpc_chx_attnbusy(fsm_instance *fsm, int event, void *arg)
  1504. {
  1505. struct channel *ch = arg;
  1506. struct net_device *dev = ch->netdev;
  1507. struct ctcm_priv *priv = dev->ml_priv;
  1508. struct mpc_group *grp = priv->mpcg;
  1509. CTCM_PR_DEBUG("%s(%s): %s\n ChState:%s GrpState:%s\n",
  1510. __func__, dev->name, ch->id,
  1511. fsm_getstate_str(ch->fsm), fsm_getstate_str(grp->fsm));
  1512. fsm_deltimer(&ch->timer);
  1513. switch (fsm_getstate(grp->fsm)) {
  1514. case MPCG_STATE_XID0IOWAIT:
  1515. /* vtam wants to be primary.start yside xid exchanges*/
  1516. /* only receive one attn-busy at a time so must not */
  1517. /* change state each time */
  1518. grp->changed_side = 1;
  1519. fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);
  1520. break;
  1521. case MPCG_STATE_XID2INITW:
  1522. if (grp->changed_side == 1) {
  1523. grp->changed_side = 2;
  1524. break;
  1525. }
  1526. /* process began via call to establish_conn */
  1527. /* so must report failure instead of reverting */
  1528. /* back to ready-for-xid passive state */
  1529. if (grp->estconnfunc)
  1530. goto done;
  1531. /* this attnbusy is NOT the result of xside xid */
  1532. /* collisions so yside must have been triggered */
  1533. /* by an ATTN that was not intended to start XID */
  1534. /* processing. Revert back to ready-for-xid and */
  1535. /* wait for ATTN interrupt to signal xid start */
  1536. if (fsm_getstate(ch->fsm) == CH_XID0_INPROGRESS) {
  1537. fsm_newstate(ch->fsm, CH_XID0_PENDING) ;
  1538. fsm_deltimer(&grp->timer);
  1539. goto done;
  1540. }
  1541. fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
  1542. goto done;
  1543. case MPCG_STATE_XID2INITX:
  1544. /* XID2 was received before ATTN Busy for second
  1545. channel.Send yside xid for second channel.
  1546. */
  1547. if (grp->changed_side == 1) {
  1548. grp->changed_side = 2;
  1549. break;
  1550. }
  1551. case MPCG_STATE_XID0IOWAIX:
  1552. case MPCG_STATE_XID7INITW:
  1553. case MPCG_STATE_XID7INITX:
  1554. case MPCG_STATE_XID7INITI:
  1555. case MPCG_STATE_XID7INITZ:
  1556. default:
  1557. /* multiple attn-busy indicates too out-of-sync */
  1558. /* and they are certainly not being received as part */
  1559. /* of valid mpc group negotiations.. */
  1560. fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
  1561. goto done;
  1562. }
  1563. if (grp->changed_side == 1) {
  1564. fsm_deltimer(&grp->timer);
  1565. fsm_addtimer(&grp->timer, MPC_XID_TIMEOUT_VALUE,
  1566. MPCG_EVENT_TIMER, dev);
  1567. }
  1568. if (ch->in_mpcgroup)
  1569. fsm_event(grp->fsm, MPCG_EVENT_XID0DO, ch);
  1570. else
  1571. CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
  1572. "%s(%s): channel %s not added to group",
  1573. CTCM_FUNTAIL, dev->name, ch->id);
  1574. done:
  1575. return;
  1576. }
  1577. /*
  1578. * ctcmpc channel FSM action
  1579. * called from several points in ctcmpc_ch_fsm
  1580. * ctcmpc only
  1581. */
  1582. static void ctcmpc_chx_resend(fsm_instance *fsm, int event, void *arg)
  1583. {
  1584. struct channel *ch = arg;
  1585. struct net_device *dev = ch->netdev;
  1586. struct ctcm_priv *priv = dev->ml_priv;
  1587. struct mpc_group *grp = priv->mpcg;
  1588. fsm_event(grp->fsm, MPCG_EVENT_XID0DO, ch);
  1589. return;
  1590. }
  1591. /*
  1592. * ctcmpc channel FSM action
  1593. * called from several points in ctcmpc_ch_fsm
  1594. * ctcmpc only
  1595. */
  1596. static void ctcmpc_chx_send_sweep(fsm_instance *fsm, int event, void *arg)
  1597. {
  1598. struct channel *ach = arg;
  1599. struct net_device *dev = ach->netdev;
  1600. struct ctcm_priv *priv = dev->ml_priv;
  1601. struct mpc_group *grp = priv->mpcg;
  1602. struct channel *wch = priv->channel[CTCM_WRITE];
  1603. struct channel *rch = priv->channel[CTCM_READ];
  1604. struct sk_buff *skb;
  1605. struct th_sweep *header;
  1606. int rc = 0;
  1607. unsigned long saveflags = 0;
  1608. CTCM_PR_DEBUG("ctcmpc enter: %s(): cp=%i ch=0x%p id=%s\n",
  1609. __func__, smp_processor_id(), ach, ach->id);
  1610. if (grp->in_sweep == 0)
  1611. goto done;
  1612. CTCM_PR_DBGDATA("%s: 1: ToVTAM_th_seq= %08x\n" ,
  1613. __func__, wch->th_seq_num);
  1614. CTCM_PR_DBGDATA("%s: 1: FromVTAM_th_seq= %08x\n" ,
  1615. __func__, rch->th_seq_num);
  1616. if (fsm_getstate(wch->fsm) != CTC_STATE_TXIDLE) {
  1617. /* give the previous IO time to complete */
  1618. fsm_addtimer(&wch->sweep_timer,
  1619. 200, CTC_EVENT_RSWEEP_TIMER, wch);
  1620. goto done;
  1621. }
  1622. skb = skb_dequeue(&wch->sweep_queue);
  1623. if (!skb)
  1624. goto done;
  1625. if (set_normalized_cda(&wch->ccw[4], skb->data)) {
  1626. grp->in_sweep = 0;
  1627. ctcm_clear_busy_do(dev);
  1628. dev_kfree_skb_any(skb);
  1629. fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
  1630. goto done;
  1631. } else {
  1632. atomic_inc(&skb->users);
  1633. skb_queue_tail(&wch->io_queue, skb);
  1634. }
  1635. /* send out the sweep */
  1636. wch->ccw[4].count = skb->len;
  1637. header = (struct th_sweep *)skb->data;
  1638. switch (header->th.th_ch_flag) {
  1639. case TH_SWEEP_REQ:
  1640. grp->sweep_req_pend_num--;
  1641. break;
  1642. case TH_SWEEP_RESP:
  1643. grp->sweep_rsp_pend_num--;
  1644. break;
  1645. }
  1646. header->sw.th_last_seq = wch->th_seq_num;
  1647. CTCM_CCW_DUMP((char *)&wch->ccw[3], sizeof(struct ccw1) * 3);
  1648. CTCM_PR_DBGDATA("%s: sweep packet\n", __func__);
  1649. CTCM_D3_DUMP((char *)header, TH_SWEEP_LENGTH);
  1650. fsm_addtimer(&wch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, wch);
  1651. fsm_newstate(wch->fsm, CTC_STATE_TX);
  1652. spin_lock_irqsave(get_ccwdev_lock(wch->cdev), saveflags);
  1653. wch->prof.send_stamp = jiffies;
  1654. rc = ccw_device_start(wch->cdev, &wch->ccw[3],
  1655. (unsigned long) wch, 0xff, 0);
  1656. spin_unlock_irqrestore(get_ccwdev_lock(wch->cdev), saveflags);
  1657. if ((grp->sweep_req_pend_num == 0) &&
  1658. (grp->sweep_rsp_pend_num == 0)) {
  1659. grp->in_sweep = 0;
  1660. rch->th_seq_num = 0x00;
  1661. wch->th_seq_num = 0x00;
  1662. ctcm_clear_busy_do(dev);
  1663. }
  1664. CTCM_PR_DBGDATA("%s: To-/From-VTAM_th_seq = %08x/%08x\n" ,
  1665. __func__, wch->th_seq_num, rch->th_seq_num);
  1666. if (rc != 0)
  1667. ctcm_ccw_check_rc(wch, rc, "send sweep");
  1668. done:
  1669. return;
  1670. }
  1671. /*
  1672. * The ctcmpc statemachine for a channel.
  1673. */
  1674. const fsm_node ctcmpc_ch_fsm[] = {
  1675. { CTC_STATE_STOPPED, CTC_EVENT_STOP, ctcm_action_nop },
  1676. { CTC_STATE_STOPPED, CTC_EVENT_START, ctcm_chx_start },
  1677. { CTC_STATE_STOPPED, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1678. { CTC_STATE_STOPPED, CTC_EVENT_FINSTAT, ctcm_action_nop },
  1679. { CTC_STATE_STOPPED, CTC_EVENT_MC_FAIL, ctcm_action_nop },
  1680. { CTC_STATE_NOTOP, CTC_EVENT_STOP, ctcm_chx_stop },
  1681. { CTC_STATE_NOTOP, CTC_EVENT_START, ctcm_action_nop },
  1682. { CTC_STATE_NOTOP, CTC_EVENT_FINSTAT, ctcm_action_nop },
  1683. { CTC_STATE_NOTOP, CTC_EVENT_MC_FAIL, ctcm_action_nop },
  1684. { CTC_STATE_NOTOP, CTC_EVENT_MC_GOOD, ctcm_chx_start },
  1685. { CTC_STATE_NOTOP, CTC_EVENT_UC_RCRESET, ctcm_chx_stop },
  1686. { CTC_STATE_NOTOP, CTC_EVENT_UC_RSRESET, ctcm_chx_stop },
  1687. { CTC_STATE_NOTOP, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1688. { CTC_STATE_STARTWAIT, CTC_EVENT_STOP, ctcm_chx_haltio },
  1689. { CTC_STATE_STARTWAIT, CTC_EVENT_START, ctcm_action_nop },
  1690. { CTC_STATE_STARTWAIT, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
  1691. { CTC_STATE_STARTWAIT, CTC_EVENT_TIMER, ctcm_chx_setuperr },
  1692. { CTC_STATE_STARTWAIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1693. { CTC_STATE_STARTWAIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1694. { CTC_STATE_STARTRETRY, CTC_EVENT_STOP, ctcm_chx_haltio },
  1695. { CTC_STATE_STARTRETRY, CTC_EVENT_TIMER, ctcm_chx_setmode },
  1696. { CTC_STATE_STARTRETRY, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
  1697. { CTC_STATE_STARTRETRY, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1698. { CTC_STATE_STARTRETRY, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1699. { CTC_STATE_SETUPWAIT, CTC_EVENT_STOP, ctcm_chx_haltio },
  1700. { CTC_STATE_SETUPWAIT, CTC_EVENT_START, ctcm_action_nop },
  1701. { CTC_STATE_SETUPWAIT, CTC_EVENT_FINSTAT, ctcmpc_chx_firstio },
  1702. { CTC_STATE_SETUPWAIT, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
  1703. { CTC_STATE_SETUPWAIT, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
  1704. { CTC_STATE_SETUPWAIT, CTC_EVENT_TIMER, ctcm_chx_setmode },
  1705. { CTC_STATE_SETUPWAIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1706. { CTC_STATE_SETUPWAIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1707. { CTC_STATE_RXINIT, CTC_EVENT_STOP, ctcm_chx_haltio },
  1708. { CTC_STATE_RXINIT, CTC_EVENT_START, ctcm_action_nop },
  1709. { CTC_STATE_RXINIT, CTC_EVENT_FINSTAT, ctcmpc_chx_rxidle },
  1710. { CTC_STATE_RXINIT, CTC_EVENT_UC_RCRESET, ctcm_chx_rxiniterr },
  1711. { CTC_STATE_RXINIT, CTC_EVENT_UC_RSRESET, ctcm_chx_rxiniterr },
  1712. { CTC_STATE_RXINIT, CTC_EVENT_TIMER, ctcm_chx_rxiniterr },
  1713. { CTC_STATE_RXINIT, CTC_EVENT_ATTNBUSY, ctcm_chx_rxinitfail },
  1714. { CTC_STATE_RXINIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1715. { CTC_STATE_RXINIT, CTC_EVENT_UC_ZERO, ctcmpc_chx_firstio },
  1716. { CTC_STATE_RXINIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1717. { CH_XID0_PENDING, CTC_EVENT_FINSTAT, ctcm_action_nop },
  1718. { CH_XID0_PENDING, CTC_EVENT_ATTN, ctcmpc_chx_attn },
  1719. { CH_XID0_PENDING, CTC_EVENT_STOP, ctcm_chx_haltio },
  1720. { CH_XID0_PENDING, CTC_EVENT_START, ctcm_action_nop },
  1721. { CH_XID0_PENDING, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1722. { CH_XID0_PENDING, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1723. { CH_XID0_PENDING, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
  1724. { CH_XID0_PENDING, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
  1725. { CH_XID0_PENDING, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
  1726. { CH_XID0_PENDING, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
  1727. { CH_XID0_INPROGRESS, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
  1728. { CH_XID0_INPROGRESS, CTC_EVENT_ATTN, ctcmpc_chx_attn },
  1729. { CH_XID0_INPROGRESS, CTC_EVENT_STOP, ctcm_chx_haltio },
  1730. { CH_XID0_INPROGRESS, CTC_EVENT_START, ctcm_action_nop },
  1731. { CH_XID0_INPROGRESS, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1732. { CH_XID0_INPROGRESS, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1733. { CH_XID0_INPROGRESS, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
  1734. { CH_XID0_INPROGRESS, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
  1735. { CH_XID0_INPROGRESS, CTC_EVENT_ATTNBUSY, ctcmpc_chx_attnbusy },
  1736. { CH_XID0_INPROGRESS, CTC_EVENT_TIMER, ctcmpc_chx_resend },
  1737. { CH_XID0_INPROGRESS, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
  1738. { CH_XID7_PENDING, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
  1739. { CH_XID7_PENDING, CTC_EVENT_ATTN, ctcmpc_chx_attn },
  1740. { CH_XID7_PENDING, CTC_EVENT_STOP, ctcm_chx_haltio },
  1741. { CH_XID7_PENDING, CTC_EVENT_START, ctcm_action_nop },
  1742. { CH_XID7_PENDING, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1743. { CH_XID7_PENDING, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1744. { CH_XID7_PENDING, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
  1745. { CH_XID7_PENDING, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
  1746. { CH_XID7_PENDING, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
  1747. { CH_XID7_PENDING, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
  1748. { CH_XID7_PENDING, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
  1749. { CH_XID7_PENDING, CTC_EVENT_TIMER, ctcmpc_chx_resend },
  1750. { CH_XID7_PENDING, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
  1751. { CH_XID7_PENDING1, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
  1752. { CH_XID7_PENDING1, CTC_EVENT_ATTN, ctcmpc_chx_attn },
  1753. { CH_XID7_PENDING1, CTC_EVENT_STOP, ctcm_chx_haltio },
  1754. { CH_XID7_PENDING1, CTC_EVENT_START, ctcm_action_nop },
  1755. { CH_XID7_PENDING1, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1756. { CH_XID7_PENDING1, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1757. { CH_XID7_PENDING1, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
  1758. { CH_XID7_PENDING1, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
  1759. { CH_XID7_PENDING1, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
  1760. { CH_XID7_PENDING1, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
  1761. { CH_XID7_PENDING1, CTC_EVENT_TIMER, ctcmpc_chx_resend },
  1762. { CH_XID7_PENDING1, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
  1763. { CH_XID7_PENDING2, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
  1764. { CH_XID7_PENDING2, CTC_EVENT_ATTN, ctcmpc_chx_attn },
  1765. { CH_XID7_PENDING2, CTC_EVENT_STOP, ctcm_chx_haltio },
  1766. { CH_XID7_PENDING2, CTC_EVENT_START, ctcm_action_nop },
  1767. { CH_XID7_PENDING2, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1768. { CH_XID7_PENDING2, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1769. { CH_XID7_PENDING2, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
  1770. { CH_XID7_PENDING2, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
  1771. { CH_XID7_PENDING2, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
  1772. { CH_XID7_PENDING2, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
  1773. { CH_XID7_PENDING2, CTC_EVENT_TIMER, ctcmpc_chx_resend },
  1774. { CH_XID7_PENDING2, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
  1775. { CH_XID7_PENDING3, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
  1776. { CH_XID7_PENDING3, CTC_EVENT_ATTN, ctcmpc_chx_attn },
  1777. { CH_XID7_PENDING3, CTC_EVENT_STOP, ctcm_chx_haltio },
  1778. { CH_XID7_PENDING3, CTC_EVENT_START, ctcm_action_nop },
  1779. { CH_XID7_PENDING3, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1780. { CH_XID7_PENDING3, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1781. { CH_XID7_PENDING3, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
  1782. { CH_XID7_PENDING3, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
  1783. { CH_XID7_PENDING3, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
  1784. { CH_XID7_PENDING3, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
  1785. { CH_XID7_PENDING3, CTC_EVENT_TIMER, ctcmpc_chx_resend },
  1786. { CH_XID7_PENDING3, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
  1787. { CH_XID7_PENDING4, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
  1788. { CH_XID7_PENDING4, CTC_EVENT_ATTN, ctcmpc_chx_attn },
  1789. { CH_XID7_PENDING4, CTC_EVENT_STOP, ctcm_chx_haltio },
  1790. { CH_XID7_PENDING4, CTC_EVENT_START, ctcm_action_nop },
  1791. { CH_XID7_PENDING4, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1792. { CH_XID7_PENDING4, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1793. { CH_XID7_PENDING4, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
  1794. { CH_XID7_PENDING4, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
  1795. { CH_XID7_PENDING4, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
  1796. { CH_XID7_PENDING4, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
  1797. { CH_XID7_PENDING4, CTC_EVENT_TIMER, ctcmpc_chx_resend },
  1798. { CH_XID7_PENDING4, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
  1799. { CTC_STATE_RXIDLE, CTC_EVENT_STOP, ctcm_chx_haltio },
  1800. { CTC_STATE_RXIDLE, CTC_EVENT_START, ctcm_action_nop },
  1801. { CTC_STATE_RXIDLE, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
  1802. { CTC_STATE_RXIDLE, CTC_EVENT_UC_RCRESET, ctcm_chx_rxdisc },
  1803. { CTC_STATE_RXIDLE, CTC_EVENT_UC_RSRESET, ctcm_chx_fail },
  1804. { CTC_STATE_RXIDLE, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1805. { CTC_STATE_RXIDLE, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1806. { CTC_STATE_RXIDLE, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
  1807. { CTC_STATE_TXINIT, CTC_EVENT_STOP, ctcm_chx_haltio },
  1808. { CTC_STATE_TXINIT, CTC_EVENT_START, ctcm_action_nop },
  1809. { CTC_STATE_TXINIT, CTC_EVENT_FINSTAT, ctcm_chx_txidle },
  1810. { CTC_STATE_TXINIT, CTC_EVENT_UC_RCRESET, ctcm_chx_txiniterr },
  1811. { CTC_STATE_TXINIT, CTC_EVENT_UC_RSRESET, ctcm_chx_txiniterr },
  1812. { CTC_STATE_TXINIT, CTC_EVENT_TIMER, ctcm_chx_txiniterr },
  1813. { CTC_STATE_TXINIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1814. { CTC_STATE_TXINIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1815. { CTC_STATE_TXINIT, CTC_EVENT_RSWEEP_TIMER, ctcmpc_chx_send_sweep },
  1816. { CTC_STATE_TXIDLE, CTC_EVENT_STOP, ctcm_chx_haltio },
  1817. { CTC_STATE_TXIDLE, CTC_EVENT_START, ctcm_action_nop },
  1818. { CTC_STATE_TXIDLE, CTC_EVENT_FINSTAT, ctcmpc_chx_firstio },
  1819. { CTC_STATE_TXIDLE, CTC_EVENT_UC_RCRESET, ctcm_chx_fail },
  1820. { CTC_STATE_TXIDLE, CTC_EVENT_UC_RSRESET, ctcm_chx_fail },
  1821. { CTC_STATE_TXIDLE, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1822. { CTC_STATE_TXIDLE, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1823. { CTC_STATE_TXIDLE, CTC_EVENT_RSWEEP_TIMER, ctcmpc_chx_send_sweep },
  1824. { CTC_STATE_TERM, CTC_EVENT_STOP, ctcm_action_nop },
  1825. { CTC_STATE_TERM, CTC_EVENT_START, ctcm_chx_restart },
  1826. { CTC_STATE_TERM, CTC_EVENT_FINSTAT, ctcm_chx_stopped },
  1827. { CTC_STATE_TERM, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
  1828. { CTC_STATE_TERM, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
  1829. { CTC_STATE_TERM, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1830. { CTC_STATE_TERM, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
  1831. { CTC_STATE_TERM, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1832. { CTC_STATE_DTERM, CTC_EVENT_STOP, ctcm_chx_haltio },
  1833. { CTC_STATE_DTERM, CTC_EVENT_START, ctcm_chx_restart },
  1834. { CTC_STATE_DTERM, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
  1835. { CTC_STATE_DTERM, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
  1836. { CTC_STATE_DTERM, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
  1837. { CTC_STATE_DTERM, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1838. { CTC_STATE_DTERM, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1839. { CTC_STATE_TX, CTC_EVENT_STOP, ctcm_chx_haltio },
  1840. { CTC_STATE_TX, CTC_EVENT_START, ctcm_action_nop },
  1841. { CTC_STATE_TX, CTC_EVENT_FINSTAT, ctcmpc_chx_txdone },
  1842. { CTC_STATE_TX, CTC_EVENT_UC_RCRESET, ctcm_chx_fail },
  1843. { CTC_STATE_TX, CTC_EVENT_UC_RSRESET, ctcm_chx_fail },
  1844. { CTC_STATE_TX, CTC_EVENT_TIMER, ctcm_chx_txretry },
  1845. { CTC_STATE_TX, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1846. { CTC_STATE_TX, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1847. { CTC_STATE_TX, CTC_EVENT_RSWEEP_TIMER, ctcmpc_chx_send_sweep },
  1848. { CTC_STATE_TX, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
  1849. { CTC_STATE_RXERR, CTC_EVENT_STOP, ctcm_chx_haltio },
  1850. { CTC_STATE_TXERR, CTC_EVENT_STOP, ctcm_chx_haltio },
  1851. { CTC_STATE_TXERR, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
  1852. { CTC_STATE_TXERR, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1853. { CTC_STATE_RXERR, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
  1854. };
  1855. int mpc_ch_fsm_len = ARRAY_SIZE(ctcmpc_ch_fsm);
  1856. /*
  1857. * Actions for interface - statemachine.
  1858. */
  1859. /**
  1860. * Startup channels by sending CTC_EVENT_START to each channel.
  1861. *
  1862. * fi An instance of an interface statemachine.
  1863. * event The event, just happened.
  1864. * arg Generic pointer, casted from struct net_device * upon call.
  1865. */
  1866. static void dev_action_start(fsm_instance *fi, int event, void *arg)
  1867. {
  1868. struct net_device *dev = arg;
  1869. struct ctcm_priv *priv = dev->ml_priv;
  1870. int direction;
  1871. CTCMY_DBF_DEV_NAME(SETUP, dev, "");
  1872. fsm_deltimer(&priv->restart_timer);
  1873. fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
  1874. if (IS_MPC(priv))
  1875. priv->mpcg->channels_terminating = 0;
  1876. for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
  1877. struct channel *ch = priv->channel[direction];
  1878. fsm_event(ch->fsm, CTC_EVENT_START, ch);
  1879. }
  1880. }
  1881. /**
  1882. * Shutdown channels by sending CTC_EVENT_STOP to each channel.
  1883. *
  1884. * fi An instance of an interface statemachine.
  1885. * event The event, just happened.
  1886. * arg Generic pointer, casted from struct net_device * upon call.
  1887. */
  1888. static void dev_action_stop(fsm_instance *fi, int event, void *arg)
  1889. {
  1890. int direction;
  1891. struct net_device *dev = arg;
  1892. struct ctcm_priv *priv = dev->ml_priv;
  1893. CTCMY_DBF_DEV_NAME(SETUP, dev, "");
  1894. fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
  1895. for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
  1896. struct channel *ch = priv->channel[direction];
  1897. fsm_event(ch->fsm, CTC_EVENT_STOP, ch);
  1898. ch->th_seq_num = 0x00;
  1899. CTCM_PR_DEBUG("%s: CH_th_seq= %08x\n",
  1900. __func__, ch->th_seq_num);
  1901. }
  1902. if (IS_MPC(priv))
  1903. fsm_newstate(priv->mpcg->fsm, MPCG_STATE_RESET);
  1904. }
  1905. static void dev_action_restart(fsm_instance *fi, int event, void *arg)
  1906. {
  1907. int restart_timer;
  1908. struct net_device *dev = arg;
  1909. struct ctcm_priv *priv = dev->ml_priv;
  1910. CTCMY_DBF_DEV_NAME(TRACE, dev, "");
  1911. if (IS_MPC(priv)) {
  1912. restart_timer = CTCM_TIME_1_SEC;
  1913. } else {
  1914. restart_timer = CTCM_TIME_5_SEC;
  1915. }
  1916. dev_info(&dev->dev, "Restarting device\n");
  1917. dev_action_stop(fi, event, arg);
  1918. fsm_event(priv->fsm, DEV_EVENT_STOP, dev);
  1919. if (IS_MPC(priv))
  1920. fsm_newstate(priv->mpcg->fsm, MPCG_STATE_RESET);
  1921. /* going back into start sequence too quickly can */
  1922. /* result in the other side becoming unreachable due */
  1923. /* to sense reported when IO is aborted */
  1924. fsm_addtimer(&priv->restart_timer, restart_timer,
  1925. DEV_EVENT_START, dev);
  1926. }
  1927. /**
  1928. * Called from channel statemachine
  1929. * when a channel is up and running.
  1930. *
  1931. * fi An instance of an interface statemachine.
  1932. * event The event, just happened.
  1933. * arg Generic pointer, casted from struct net_device * upon call.
  1934. */
  1935. static void dev_action_chup(fsm_instance *fi, int event, void *arg)
  1936. {
  1937. struct net_device *dev = arg;
  1938. struct ctcm_priv *priv = dev->ml_priv;
  1939. int dev_stat = fsm_getstate(fi);
  1940. CTCM_DBF_TEXT_(SETUP, CTC_DBF_NOTICE,
  1941. "%s(%s): priv = %p [%d,%d]\n ", CTCM_FUNTAIL,
  1942. dev->name, dev->ml_priv, dev_stat, event);
  1943. switch (fsm_getstate(fi)) {
  1944. case DEV_STATE_STARTWAIT_RXTX:
  1945. if (event == DEV_EVENT_RXUP)
  1946. fsm_newstate(fi, DEV_STATE_STARTWAIT_TX);
  1947. else
  1948. fsm_newstate(fi, DEV_STATE_STARTWAIT_RX);
  1949. break;
  1950. case DEV_STATE_STARTWAIT_RX:
  1951. if (event == DEV_EVENT_RXUP) {
  1952. fsm_newstate(fi, DEV_STATE_RUNNING);
  1953. dev_info(&dev->dev,
  1954. "Connected with remote side\n");
  1955. ctcm_clear_busy(dev);
  1956. }
  1957. break;
  1958. case DEV_STATE_STARTWAIT_TX:
  1959. if (event == DEV_EVENT_TXUP) {
  1960. fsm_newstate(fi, DEV_STATE_RUNNING);
  1961. dev_info(&dev->dev,
  1962. "Connected with remote side\n");
  1963. ctcm_clear_busy(dev);
  1964. }
  1965. break;
  1966. case DEV_STATE_STOPWAIT_TX:
  1967. if (event == DEV_EVENT_RXUP)
  1968. fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
  1969. break;
  1970. case DEV_STATE_STOPWAIT_RX:
  1971. if (event == DEV_EVENT_TXUP)
  1972. fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
  1973. break;
  1974. }
  1975. if (IS_MPC(priv)) {
  1976. if (event == DEV_EVENT_RXUP)
  1977. mpc_channel_action(priv->channel[CTCM_READ],
  1978. CTCM_READ, MPC_CHANNEL_ADD);
  1979. else
  1980. mpc_channel_action(priv->channel[CTCM_WRITE],
  1981. CTCM_WRITE, MPC_CHANNEL_ADD);
  1982. }
  1983. }
  1984. /**
  1985. * Called from device statemachine
  1986. * when a channel has been shutdown.
  1987. *
  1988. * fi An instance of an interface statemachine.
  1989. * event The event, just happened.
  1990. * arg Generic pointer, casted from struct net_device * upon call.
  1991. */
  1992. static void dev_action_chdown(fsm_instance *fi, int event, void *arg)
  1993. {
  1994. struct net_device *dev = arg;
  1995. struct ctcm_priv *priv = dev->ml_priv;
  1996. CTCMY_DBF_DEV_NAME(SETUP, dev, "");
  1997. switch (fsm_getstate(fi)) {
  1998. case DEV_STATE_RUNNING:
  1999. if (event == DEV_EVENT_TXDOWN)
  2000. fsm_newstate(fi, DEV_STATE_STARTWAIT_TX);
  2001. else
  2002. fsm_newstate(fi, DEV_STATE_STARTWAIT_RX);
  2003. break;
  2004. case DEV_STATE_STARTWAIT_RX:
  2005. if (event == DEV_EVENT_TXDOWN)
  2006. fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
  2007. break;
  2008. case DEV_STATE_STARTWAIT_TX:
  2009. if (event == DEV_EVENT_RXDOWN)
  2010. fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
  2011. break;
  2012. case DEV_STATE_STOPWAIT_RXTX:
  2013. if (event == DEV_EVENT_TXDOWN)
  2014. fsm_newstate(fi, DEV_STATE_STOPWAIT_RX);
  2015. else
  2016. fsm_newstate(fi, DEV_STATE_STOPWAIT_TX);
  2017. break;
  2018. case DEV_STATE_STOPWAIT_RX:
  2019. if (event == DEV_EVENT_RXDOWN)
  2020. fsm_newstate(fi, DEV_STATE_STOPPED);
  2021. break;
  2022. case DEV_STATE_STOPWAIT_TX:
  2023. if (event == DEV_EVENT_TXDOWN)
  2024. fsm_newstate(fi, DEV_STATE_STOPPED);
  2025. break;
  2026. }
  2027. if (IS_MPC(priv)) {
  2028. if (event == DEV_EVENT_RXDOWN)
  2029. mpc_channel_action(priv->channel[CTCM_READ],
  2030. CTCM_READ, MPC_CHANNEL_REMOVE);
  2031. else
  2032. mpc_channel_action(priv->channel[CTCM_WRITE],
  2033. CTCM_WRITE, MPC_CHANNEL_REMOVE);
  2034. }
  2035. }
  2036. const fsm_node dev_fsm[] = {
  2037. { DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start },
  2038. { DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_START, dev_action_start },
  2039. { DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_RXDOWN, dev_action_chdown },
  2040. { DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_TXDOWN, dev_action_chdown },
  2041. { DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_RESTART, dev_action_restart },
  2042. { DEV_STATE_STOPWAIT_RX, DEV_EVENT_START, dev_action_start },
  2043. { DEV_STATE_STOPWAIT_RX, DEV_EVENT_RXUP, dev_action_chup },
  2044. { DEV_STATE_STOPWAIT_RX, DEV_EVENT_TXUP, dev_action_chup },
  2045. { DEV_STATE_STOPWAIT_RX, DEV_EVENT_RXDOWN, dev_action_chdown },
  2046. { DEV_STATE_STOPWAIT_RX, DEV_EVENT_RESTART, dev_action_restart },
  2047. { DEV_STATE_STOPWAIT_TX, DEV_EVENT_START, dev_action_start },
  2048. { DEV_STATE_STOPWAIT_TX, DEV_EVENT_RXUP, dev_action_chup },
  2049. { DEV_STATE_STOPWAIT_TX, DEV_EVENT_TXUP, dev_action_chup },
  2050. { DEV_STATE_STOPWAIT_TX, DEV_EVENT_TXDOWN, dev_action_chdown },
  2051. { DEV_STATE_STOPWAIT_TX, DEV_EVENT_RESTART, dev_action_restart },
  2052. { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_STOP, dev_action_stop },
  2053. { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RXUP, dev_action_chup },
  2054. { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_TXUP, dev_action_chup },
  2055. { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RXDOWN, dev_action_chdown },
  2056. { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_TXDOWN, dev_action_chdown },
  2057. { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RESTART, dev_action_restart },
  2058. { DEV_STATE_STARTWAIT_TX, DEV_EVENT_STOP, dev_action_stop },
  2059. { DEV_STATE_STARTWAIT_TX, DEV_EVENT_RXUP, dev_action_chup },
  2060. { DEV_STATE_STARTWAIT_TX, DEV_EVENT_TXUP, dev_action_chup },
  2061. { DEV_STATE_STARTWAIT_TX, DEV_EVENT_RXDOWN, dev_action_chdown },
  2062. { DEV_STATE_STARTWAIT_TX, DEV_EVENT_RESTART, dev_action_restart },
  2063. { DEV_STATE_STARTWAIT_RX, DEV_EVENT_STOP, dev_action_stop },
  2064. { DEV_STATE_STARTWAIT_RX, DEV_EVENT_RXUP, dev_action_chup },
  2065. { DEV_STATE_STARTWAIT_RX, DEV_EVENT_TXUP, dev_action_chup },
  2066. { DEV_STATE_STARTWAIT_RX, DEV_EVENT_TXDOWN, dev_action_chdown },
  2067. { DEV_STATE_STARTWAIT_RX, DEV_EVENT_RESTART, dev_action_restart },
  2068. { DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop },
  2069. { DEV_STATE_RUNNING, DEV_EVENT_RXDOWN, dev_action_chdown },
  2070. { DEV_STATE_RUNNING, DEV_EVENT_TXDOWN, dev_action_chdown },
  2071. { DEV_STATE_RUNNING, DEV_EVENT_TXUP, ctcm_action_nop },
  2072. { DEV_STATE_RUNNING, DEV_EVENT_RXUP, ctcm_action_nop },
  2073. { DEV_STATE_RUNNING, DEV_EVENT_RESTART, dev_action_restart },
  2074. };
  2075. int dev_fsm_len = ARRAY_SIZE(dev_fsm);
  2076. /* --- This is the END my friend --- */