ctcm_fsms.c 75 KB

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