ctcm_fsms.c 74 KB

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