12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300 |
- /*
- * Copyright IBM Corp. 2001, 2007
- * Authors: Fritz Elfert (felfert@millenux.com)
- * Peter Tiedemann (ptiedem@de.ibm.com)
- * MPC additions :
- * Belinda Thompson (belindat@us.ibm.com)
- * Andy Richter (richtera@us.ibm.com)
- */
- #undef DEBUG
- #undef DEBUGDATA
- #undef DEBUGCCW
- #define KMSG_COMPONENT "ctcm"
- #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/kernel.h>
- #include <linux/slab.h>
- #include <linux/errno.h>
- #include <linux/types.h>
- #include <linux/interrupt.h>
- #include <linux/timer.h>
- #include <linux/bitops.h>
- #include <linux/signal.h>
- #include <linux/string.h>
- #include <linux/ip.h>
- #include <linux/if_arp.h>
- #include <linux/tcp.h>
- #include <linux/skbuff.h>
- #include <linux/ctype.h>
- #include <net/dst.h>
- #include <linux/io.h>
- #include <asm/ccwdev.h>
- #include <asm/ccwgroup.h>
- #include <linux/uaccess.h>
- #include <asm/idals.h>
- #include "fsm.h"
- #include "ctcm_dbug.h"
- #include "ctcm_main.h"
- #include "ctcm_fsms.h"
- const char *dev_state_names[] = {
- [DEV_STATE_STOPPED] = "Stopped",
- [DEV_STATE_STARTWAIT_RXTX] = "StartWait RXTX",
- [DEV_STATE_STARTWAIT_RX] = "StartWait RX",
- [DEV_STATE_STARTWAIT_TX] = "StartWait TX",
- [DEV_STATE_STOPWAIT_RXTX] = "StopWait RXTX",
- [DEV_STATE_STOPWAIT_RX] = "StopWait RX",
- [DEV_STATE_STOPWAIT_TX] = "StopWait TX",
- [DEV_STATE_RUNNING] = "Running",
- };
- const char *dev_event_names[] = {
- [DEV_EVENT_START] = "Start",
- [DEV_EVENT_STOP] = "Stop",
- [DEV_EVENT_RXUP] = "RX up",
- [DEV_EVENT_TXUP] = "TX up",
- [DEV_EVENT_RXDOWN] = "RX down",
- [DEV_EVENT_TXDOWN] = "TX down",
- [DEV_EVENT_RESTART] = "Restart",
- };
- const char *ctc_ch_event_names[] = {
- [CTC_EVENT_IO_SUCCESS] = "ccw_device success",
- [CTC_EVENT_IO_EBUSY] = "ccw_device busy",
- [CTC_EVENT_IO_ENODEV] = "ccw_device enodev",
- [CTC_EVENT_IO_UNKNOWN] = "ccw_device unknown",
- [CTC_EVENT_ATTNBUSY] = "Status ATTN & BUSY",
- [CTC_EVENT_ATTN] = "Status ATTN",
- [CTC_EVENT_BUSY] = "Status BUSY",
- [CTC_EVENT_UC_RCRESET] = "Unit check remote reset",
- [CTC_EVENT_UC_RSRESET] = "Unit check remote system reset",
- [CTC_EVENT_UC_TXTIMEOUT] = "Unit check TX timeout",
- [CTC_EVENT_UC_TXPARITY] = "Unit check TX parity",
- [CTC_EVENT_UC_HWFAIL] = "Unit check Hardware failure",
- [CTC_EVENT_UC_RXPARITY] = "Unit check RX parity",
- [CTC_EVENT_UC_ZERO] = "Unit check ZERO",
- [CTC_EVENT_UC_UNKNOWN] = "Unit check Unknown",
- [CTC_EVENT_SC_UNKNOWN] = "SubChannel check Unknown",
- [CTC_EVENT_MC_FAIL] = "Machine check failure",
- [CTC_EVENT_MC_GOOD] = "Machine check operational",
- [CTC_EVENT_IRQ] = "IRQ normal",
- [CTC_EVENT_FINSTAT] = "IRQ final",
- [CTC_EVENT_TIMER] = "Timer",
- [CTC_EVENT_START] = "Start",
- [CTC_EVENT_STOP] = "Stop",
- /*
- * additional MPC events
- */
- [CTC_EVENT_SEND_XID] = "XID Exchange",
- [CTC_EVENT_RSWEEP_TIMER] = "MPC Group Sweep Timer",
- };
- const char *ctc_ch_state_names[] = {
- [CTC_STATE_IDLE] = "Idle",
- [CTC_STATE_STOPPED] = "Stopped",
- [CTC_STATE_STARTWAIT] = "StartWait",
- [CTC_STATE_STARTRETRY] = "StartRetry",
- [CTC_STATE_SETUPWAIT] = "SetupWait",
- [CTC_STATE_RXINIT] = "RX init",
- [CTC_STATE_TXINIT] = "TX init",
- [CTC_STATE_RX] = "RX",
- [CTC_STATE_TX] = "TX",
- [CTC_STATE_RXIDLE] = "RX idle",
- [CTC_STATE_TXIDLE] = "TX idle",
- [CTC_STATE_RXERR] = "RX error",
- [CTC_STATE_TXERR] = "TX error",
- [CTC_STATE_TERM] = "Terminating",
- [CTC_STATE_DTERM] = "Restarting",
- [CTC_STATE_NOTOP] = "Not operational",
- /*
- * additional MPC states
- */
- [CH_XID0_PENDING] = "Pending XID0 Start",
- [CH_XID0_INPROGRESS] = "In XID0 Negotiations ",
- [CH_XID7_PENDING] = "Pending XID7 P1 Start",
- [CH_XID7_PENDING1] = "Active XID7 P1 Exchange ",
- [CH_XID7_PENDING2] = "Pending XID7 P2 Start ",
- [CH_XID7_PENDING3] = "Active XID7 P2 Exchange ",
- [CH_XID7_PENDING4] = "XID7 Complete - Pending READY ",
- };
- static void ctcm_action_nop(fsm_instance *fi, int event, void *arg);
- /*
- * ----- static ctcm actions for channel statemachine -----
- *
- */
- static void chx_txdone(fsm_instance *fi, int event, void *arg);
- static void chx_rx(fsm_instance *fi, int event, void *arg);
- static void chx_rxidle(fsm_instance *fi, int event, void *arg);
- static void chx_firstio(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_setmode(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_start(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_haltio(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_stopped(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_stop(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_fail(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_setuperr(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_restart(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_rxiniterr(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_rxinitfail(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_rxdisc(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_txiniterr(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_txretry(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_iofatal(fsm_instance *fi, int event, void *arg);
- /*
- * ----- static ctcmpc actions for ctcmpc channel statemachine -----
- *
- */
- static void ctcmpc_chx_txdone(fsm_instance *fi, int event, void *arg);
- static void ctcmpc_chx_rx(fsm_instance *fi, int event, void *arg);
- static void ctcmpc_chx_firstio(fsm_instance *fi, int event, void *arg);
- /* shared :
- static void ctcm_chx_setmode(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_start(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_haltio(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_stopped(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_stop(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_fail(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_setuperr(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_restart(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_rxiniterr(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_rxinitfail(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_rxdisc(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_txiniterr(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_txretry(fsm_instance *fi, int event, void *arg);
- static void ctcm_chx_iofatal(fsm_instance *fi, int event, void *arg);
- */
- static void ctcmpc_chx_attn(fsm_instance *fsm, int event, void *arg);
- static void ctcmpc_chx_attnbusy(fsm_instance *, int, void *);
- static void ctcmpc_chx_resend(fsm_instance *, int, void *);
- static void ctcmpc_chx_send_sweep(fsm_instance *fsm, int event, void *arg);
- /**
- * Check return code of a preceding ccw_device call, halt_IO etc...
- *
- * ch : The channel, the error belongs to.
- * Returns the error code (!= 0) to inspect.
- */
- void ctcm_ccw_check_rc(struct channel *ch, int rc, char *msg)
- {
- CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
- "%s(%s): %s: %04x\n",
- CTCM_FUNTAIL, ch->id, msg, rc);
- switch (rc) {
- case -EBUSY:
- pr_info("%s: The communication peer is busy\n",
- ch->id);
- fsm_event(ch->fsm, CTC_EVENT_IO_EBUSY, ch);
- break;
- case -ENODEV:
- pr_err("%s: The specified target device is not valid\n",
- ch->id);
- fsm_event(ch->fsm, CTC_EVENT_IO_ENODEV, ch);
- break;
- default:
- pr_err("An I/O operation resulted in error %04x\n",
- rc);
- fsm_event(ch->fsm, CTC_EVENT_IO_UNKNOWN, ch);
- }
- }
- void ctcm_purge_skb_queue(struct sk_buff_head *q)
- {
- struct sk_buff *skb;
- CTCM_DBF_TEXT(TRACE, CTC_DBF_DEBUG, __func__);
- while ((skb = skb_dequeue(q))) {
- atomic_dec(&skb->users);
- dev_kfree_skb_any(skb);
- }
- }
- /**
- * NOP action for statemachines
- */
- static void ctcm_action_nop(fsm_instance *fi, int event, void *arg)
- {
- }
- /*
- * Actions for channel - statemachines.
- */
- /**
- * Normal data has been send. Free the corresponding
- * skb (it's in io_queue), reset dev->tbusy and
- * revert to idle state.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void chx_txdone(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- struct sk_buff *skb;
- int first = 1;
- int i;
- unsigned long duration;
- unsigned long done_stamp = jiffies;
- CTCM_PR_DEBUG("%s(%s): %s\n", __func__, ch->id, dev->name);
- duration = done_stamp - ch->prof.send_stamp;
- if (duration > ch->prof.tx_time)
- ch->prof.tx_time = duration;
- if (ch->irb->scsw.cmd.count != 0)
- CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
- "%s(%s): TX not complete, remaining %d bytes",
- CTCM_FUNTAIL, dev->name, ch->irb->scsw.cmd.count);
- fsm_deltimer(&ch->timer);
- while ((skb = skb_dequeue(&ch->io_queue))) {
- priv->stats.tx_packets++;
- priv->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
- if (first) {
- priv->stats.tx_bytes += 2;
- first = 0;
- }
- atomic_dec(&skb->users);
- dev_kfree_skb_irq(skb);
- }
- spin_lock(&ch->collect_lock);
- clear_normalized_cda(&ch->ccw[4]);
- if (ch->collect_len > 0) {
- int rc;
- if (ctcm_checkalloc_buffer(ch)) {
- spin_unlock(&ch->collect_lock);
- return;
- }
- ch->trans_skb->data = ch->trans_skb_data;
- skb_reset_tail_pointer(ch->trans_skb);
- ch->trans_skb->len = 0;
- if (ch->prof.maxmulti < (ch->collect_len + 2))
- ch->prof.maxmulti = ch->collect_len + 2;
- if (ch->prof.maxcqueue < skb_queue_len(&ch->collect_queue))
- ch->prof.maxcqueue = skb_queue_len(&ch->collect_queue);
- *((__u16 *)skb_put(ch->trans_skb, 2)) = ch->collect_len + 2;
- i = 0;
- while ((skb = skb_dequeue(&ch->collect_queue))) {
- skb_copy_from_linear_data(skb,
- skb_put(ch->trans_skb, skb->len), skb->len);
- priv->stats.tx_packets++;
- priv->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
- atomic_dec(&skb->users);
- dev_kfree_skb_irq(skb);
- i++;
- }
- ch->collect_len = 0;
- spin_unlock(&ch->collect_lock);
- ch->ccw[1].count = ch->trans_skb->len;
- fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
- ch->prof.send_stamp = jiffies;
- rc = ccw_device_start(ch->cdev, &ch->ccw[0],
- (unsigned long)ch, 0xff, 0);
- ch->prof.doios_multi++;
- if (rc != 0) {
- priv->stats.tx_dropped += i;
- priv->stats.tx_errors += i;
- fsm_deltimer(&ch->timer);
- ctcm_ccw_check_rc(ch, rc, "chained TX");
- }
- } else {
- spin_unlock(&ch->collect_lock);
- fsm_newstate(fi, CTC_STATE_TXIDLE);
- }
- ctcm_clear_busy_do(dev);
- }
- /**
- * Initial data is sent.
- * Notify device statemachine that we are up and
- * running.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- void ctcm_chx_txidle(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- CTCM_PR_DEBUG("%s(%s): %s\n", __func__, ch->id, dev->name);
- fsm_deltimer(&ch->timer);
- fsm_newstate(fi, CTC_STATE_TXIDLE);
- fsm_event(priv->fsm, DEV_EVENT_TXUP, ch->netdev);
- }
- /**
- * Got normal data, check for sanity, queue it up, allocate new buffer
- * trigger bottom half, and initiate next read.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void chx_rx(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- int len = ch->max_bufsize - ch->irb->scsw.cmd.count;
- struct sk_buff *skb = ch->trans_skb;
- __u16 block_len = *((__u16 *)skb->data);
- int check_len;
- int rc;
- fsm_deltimer(&ch->timer);
- if (len < 8) {
- CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
- "%s(%s): got packet with length %d < 8\n",
- CTCM_FUNTAIL, dev->name, len);
- priv->stats.rx_dropped++;
- priv->stats.rx_length_errors++;
- goto again;
- }
- if (len > ch->max_bufsize) {
- CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
- "%s(%s): got packet with length %d > %d\n",
- CTCM_FUNTAIL, dev->name, len, ch->max_bufsize);
- priv->stats.rx_dropped++;
- priv->stats.rx_length_errors++;
- goto again;
- }
- /*
- * VM TCP seems to have a bug sending 2 trailing bytes of garbage.
- */
- switch (ch->protocol) {
- case CTCM_PROTO_S390:
- case CTCM_PROTO_OS390:
- check_len = block_len + 2;
- break;
- default:
- check_len = block_len;
- break;
- }
- if ((len < block_len) || (len > check_len)) {
- CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
- "%s(%s): got block length %d != rx length %d\n",
- CTCM_FUNTAIL, dev->name, block_len, len);
- if (do_debug)
- ctcmpc_dump_skb(skb, 0);
- *((__u16 *)skb->data) = len;
- priv->stats.rx_dropped++;
- priv->stats.rx_length_errors++;
- goto again;
- }
- if (block_len > 2) {
- *((__u16 *)skb->data) = block_len - 2;
- ctcm_unpack_skb(ch, skb);
- }
- again:
- skb->data = ch->trans_skb_data;
- skb_reset_tail_pointer(skb);
- skb->len = 0;
- if (ctcm_checkalloc_buffer(ch))
- return;
- ch->ccw[1].count = ch->max_bufsize;
- rc = ccw_device_start(ch->cdev, &ch->ccw[0],
- (unsigned long)ch, 0xff, 0);
- if (rc != 0)
- ctcm_ccw_check_rc(ch, rc, "normal RX");
- }
- /**
- * Initialize connection by sending a __u16 of value 0.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void chx_firstio(fsm_instance *fi, int event, void *arg)
- {
- int rc;
- struct channel *ch = arg;
- int fsmstate = fsm_getstate(fi);
- CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
- "%s(%s) : %02x",
- CTCM_FUNTAIL, ch->id, fsmstate);
- ch->sense_rc = 0; /* reset unit check report control */
- if (fsmstate == CTC_STATE_TXIDLE)
- CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
- "%s(%s): remote side issued READ?, init.\n",
- CTCM_FUNTAIL, ch->id);
- fsm_deltimer(&ch->timer);
- if (ctcm_checkalloc_buffer(ch))
- return;
- if ((fsmstate == CTC_STATE_SETUPWAIT) &&
- (ch->protocol == CTCM_PROTO_OS390)) {
- /* OS/390 resp. z/OS */
- if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
- *((__u16 *)ch->trans_skb->data) = CTCM_INITIAL_BLOCKLEN;
- fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC,
- CTC_EVENT_TIMER, ch);
- chx_rxidle(fi, event, arg);
- } else {
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- fsm_newstate(fi, CTC_STATE_TXIDLE);
- fsm_event(priv->fsm, DEV_EVENT_TXUP, dev);
- }
- return;
- }
- /*
- * Don't setup a timer for receiving the initial RX frame
- * if in compatibility mode, since VM TCP delays the initial
- * frame until it has some data to send.
- */
- if ((CHANNEL_DIRECTION(ch->flags) == CTCM_WRITE) ||
- (ch->protocol != CTCM_PROTO_S390))
- fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
- *((__u16 *)ch->trans_skb->data) = CTCM_INITIAL_BLOCKLEN;
- ch->ccw[1].count = 2; /* Transfer only length */
- fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == CTCM_READ)
- ? CTC_STATE_RXINIT : CTC_STATE_TXINIT);
- rc = ccw_device_start(ch->cdev, &ch->ccw[0],
- (unsigned long)ch, 0xff, 0);
- if (rc != 0) {
- fsm_deltimer(&ch->timer);
- fsm_newstate(fi, CTC_STATE_SETUPWAIT);
- ctcm_ccw_check_rc(ch, rc, "init IO");
- }
- /*
- * If in compatibility mode since we don't setup a timer, we
- * also signal RX channel up immediately. This enables us
- * to send packets early which in turn usually triggers some
- * reply from VM TCP which brings up the RX channel to it's
- * final state.
- */
- if ((CHANNEL_DIRECTION(ch->flags) == CTCM_READ) &&
- (ch->protocol == CTCM_PROTO_S390)) {
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- fsm_event(priv->fsm, DEV_EVENT_RXUP, dev);
- }
- }
- /**
- * Got initial data, check it. If OK,
- * notify device statemachine that we are up and
- * running.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void chx_rxidle(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- __u16 buflen;
- int rc;
- fsm_deltimer(&ch->timer);
- buflen = *((__u16 *)ch->trans_skb->data);
- CTCM_PR_DEBUG("%s: %s: Initial RX count = %d\n",
- __func__, dev->name, buflen);
- if (buflen >= CTCM_INITIAL_BLOCKLEN) {
- if (ctcm_checkalloc_buffer(ch))
- return;
- ch->ccw[1].count = ch->max_bufsize;
- fsm_newstate(fi, CTC_STATE_RXIDLE);
- rc = ccw_device_start(ch->cdev, &ch->ccw[0],
- (unsigned long)ch, 0xff, 0);
- if (rc != 0) {
- fsm_newstate(fi, CTC_STATE_RXINIT);
- ctcm_ccw_check_rc(ch, rc, "initial RX");
- } else
- fsm_event(priv->fsm, DEV_EVENT_RXUP, dev);
- } else {
- CTCM_PR_DEBUG("%s: %s: Initial RX count %d not %d\n",
- __func__, dev->name,
- buflen, CTCM_INITIAL_BLOCKLEN);
- chx_firstio(fi, event, arg);
- }
- }
- /**
- * Set channel into extended mode.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcm_chx_setmode(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- int rc;
- unsigned long saveflags = 0;
- int timeout = CTCM_TIME_5_SEC;
- fsm_deltimer(&ch->timer);
- if (IS_MPC(ch)) {
- timeout = 1500;
- CTCM_PR_DEBUG("enter %s: cp=%i ch=0x%p id=%s\n",
- __func__, smp_processor_id(), ch, ch->id);
- }
- fsm_addtimer(&ch->timer, timeout, CTC_EVENT_TIMER, ch);
- fsm_newstate(fi, CTC_STATE_SETUPWAIT);
- CTCM_CCW_DUMP((char *)&ch->ccw[6], sizeof(struct ccw1) * 2);
- if (event == CTC_EVENT_TIMER) /* only for timer not yet locked */
- spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
- /* Such conditional locking is undeterministic in
- * static view. => ignore sparse warnings here. */
- rc = ccw_device_start(ch->cdev, &ch->ccw[6],
- (unsigned long)ch, 0xff, 0);
- if (event == CTC_EVENT_TIMER) /* see above comments */
- spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
- if (rc != 0) {
- fsm_deltimer(&ch->timer);
- fsm_newstate(fi, CTC_STATE_STARTWAIT);
- ctcm_ccw_check_rc(ch, rc, "set Mode");
- } else
- ch->retry = 0;
- }
- /**
- * Setup channel.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcm_chx_start(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- unsigned long saveflags;
- int rc;
- CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s): %s",
- CTCM_FUNTAIL, ch->id,
- (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? "RX" : "TX");
- if (ch->trans_skb != NULL) {
- clear_normalized_cda(&ch->ccw[1]);
- dev_kfree_skb(ch->trans_skb);
- ch->trans_skb = NULL;
- }
- if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
- ch->ccw[1].cmd_code = CCW_CMD_READ;
- ch->ccw[1].flags = CCW_FLAG_SLI;
- ch->ccw[1].count = 0;
- } else {
- ch->ccw[1].cmd_code = CCW_CMD_WRITE;
- ch->ccw[1].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
- ch->ccw[1].count = 0;
- }
- if (ctcm_checkalloc_buffer(ch)) {
- CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
- "%s(%s): %s trans_skb alloc delayed "
- "until first transfer",
- CTCM_FUNTAIL, ch->id,
- (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ?
- "RX" : "TX");
- }
- ch->ccw[0].cmd_code = CCW_CMD_PREPARE;
- ch->ccw[0].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
- ch->ccw[0].count = 0;
- ch->ccw[0].cda = 0;
- ch->ccw[2].cmd_code = CCW_CMD_NOOP; /* jointed CE + DE */
- ch->ccw[2].flags = CCW_FLAG_SLI;
- ch->ccw[2].count = 0;
- ch->ccw[2].cda = 0;
- memcpy(&ch->ccw[3], &ch->ccw[0], sizeof(struct ccw1) * 3);
- ch->ccw[4].cda = 0;
- ch->ccw[4].flags &= ~CCW_FLAG_IDA;
- fsm_newstate(fi, CTC_STATE_STARTWAIT);
- fsm_addtimer(&ch->timer, 1000, CTC_EVENT_TIMER, ch);
- spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
- rc = ccw_device_halt(ch->cdev, (unsigned long)ch);
- spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
- if (rc != 0) {
- if (rc != -EBUSY)
- fsm_deltimer(&ch->timer);
- ctcm_ccw_check_rc(ch, rc, "initial HaltIO");
- }
- }
- /**
- * Shutdown a channel.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcm_chx_haltio(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- unsigned long saveflags = 0;
- int rc;
- int oldstate;
- fsm_deltimer(&ch->timer);
- if (IS_MPC(ch))
- fsm_deltimer(&ch->sweep_timer);
- fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
- if (event == CTC_EVENT_STOP) /* only for STOP not yet locked */
- spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
- /* Such conditional locking is undeterministic in
- * static view. => ignore sparse warnings here. */
- oldstate = fsm_getstate(fi);
- fsm_newstate(fi, CTC_STATE_TERM);
- rc = ccw_device_halt(ch->cdev, (unsigned long)ch);
- if (event == CTC_EVENT_STOP)
- spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
- /* see remark above about conditional locking */
- if (rc != 0 && rc != -EBUSY) {
- fsm_deltimer(&ch->timer);
- if (event != CTC_EVENT_STOP) {
- fsm_newstate(fi, oldstate);
- ctcm_ccw_check_rc(ch, rc, (char *)__func__);
- }
- }
- }
- /**
- * Cleanup helper for chx_fail and chx_stopped
- * cleanup channels queue and notify interface statemachine.
- *
- * fi An instance of a channel statemachine.
- * state The next state (depending on caller).
- * ch The channel to operate on.
- */
- static void ctcm_chx_cleanup(fsm_instance *fi, int state,
- struct channel *ch)
- {
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- CTCM_DBF_TEXT_(SETUP, CTC_DBF_NOTICE,
- "%s(%s): %s[%d]\n",
- CTCM_FUNTAIL, dev->name, ch->id, state);
- fsm_deltimer(&ch->timer);
- if (IS_MPC(ch))
- fsm_deltimer(&ch->sweep_timer);
- fsm_newstate(fi, state);
- if (state == CTC_STATE_STOPPED && ch->trans_skb != NULL) {
- clear_normalized_cda(&ch->ccw[1]);
- dev_kfree_skb_any(ch->trans_skb);
- ch->trans_skb = NULL;
- }
- ch->th_seg = 0x00;
- ch->th_seq_num = 0x00;
- if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
- skb_queue_purge(&ch->io_queue);
- fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
- } else {
- ctcm_purge_skb_queue(&ch->io_queue);
- if (IS_MPC(ch))
- ctcm_purge_skb_queue(&ch->sweep_queue);
- spin_lock(&ch->collect_lock);
- ctcm_purge_skb_queue(&ch->collect_queue);
- ch->collect_len = 0;
- spin_unlock(&ch->collect_lock);
- fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
- }
- }
- /**
- * A channel has successfully been halted.
- * Cleanup it's queue and notify interface statemachine.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcm_chx_stopped(fsm_instance *fi, int event, void *arg)
- {
- ctcm_chx_cleanup(fi, CTC_STATE_STOPPED, arg);
- }
- /**
- * A stop command from device statemachine arrived and we are in
- * not operational mode. Set state to stopped.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcm_chx_stop(fsm_instance *fi, int event, void *arg)
- {
- fsm_newstate(fi, CTC_STATE_STOPPED);
- }
- /**
- * A machine check for no path, not operational status or gone device has
- * happened.
- * Cleanup queue and notify interface statemachine.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcm_chx_fail(fsm_instance *fi, int event, void *arg)
- {
- ctcm_chx_cleanup(fi, CTC_STATE_NOTOP, arg);
- }
- /**
- * Handle error during setup of channel.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcm_chx_setuperr(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- /*
- * Special case: Got UC_RCRESET on setmode.
- * This means that remote side isn't setup. In this case
- * simply retry after some 10 secs...
- */
- if ((fsm_getstate(fi) == CTC_STATE_SETUPWAIT) &&
- ((event == CTC_EVENT_UC_RCRESET) ||
- (event == CTC_EVENT_UC_RSRESET))) {
- fsm_newstate(fi, CTC_STATE_STARTRETRY);
- fsm_deltimer(&ch->timer);
- fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
- if (!IS_MPC(ch) &&
- (CHANNEL_DIRECTION(ch->flags) == CTCM_READ)) {
- int rc = ccw_device_halt(ch->cdev, (unsigned long)ch);
- if (rc != 0)
- ctcm_ccw_check_rc(ch, rc,
- "HaltIO in chx_setuperr");
- }
- return;
- }
- CTCM_DBF_TEXT_(ERROR, CTC_DBF_CRIT,
- "%s(%s) : %s error during %s channel setup state=%s\n",
- CTCM_FUNTAIL, dev->name, ctc_ch_event_names[event],
- (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? "RX" : "TX",
- fsm_getstate_str(fi));
- if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
- fsm_newstate(fi, CTC_STATE_RXERR);
- fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
- } else {
- fsm_newstate(fi, CTC_STATE_TXERR);
- fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
- }
- }
- /**
- * Restart a channel after an error.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcm_chx_restart(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- unsigned long saveflags = 0;
- int oldstate;
- int rc;
- CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
- "%s: %s[%d] of %s\n",
- CTCM_FUNTAIL, ch->id, event, dev->name);
- fsm_deltimer(&ch->timer);
- fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
- oldstate = fsm_getstate(fi);
- fsm_newstate(fi, CTC_STATE_STARTWAIT);
- if (event == CTC_EVENT_TIMER) /* only for timer not yet locked */
- spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
- /* Such conditional locking is a known problem for
- * sparse because its undeterministic in static view.
- * Warnings should be ignored here. */
- rc = ccw_device_halt(ch->cdev, (unsigned long)ch);
- if (event == CTC_EVENT_TIMER)
- spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
- if (rc != 0) {
- if (rc != -EBUSY) {
- fsm_deltimer(&ch->timer);
- fsm_newstate(fi, oldstate);
- }
- ctcm_ccw_check_rc(ch, rc, "HaltIO in ctcm_chx_restart");
- }
- }
- /**
- * Handle error during RX initial handshake (exchange of
- * 0-length block header)
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcm_chx_rxiniterr(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- if (event == CTC_EVENT_TIMER) {
- if (!IS_MPCDEV(dev))
- /* TODO : check if MPC deletes timer somewhere */
- fsm_deltimer(&ch->timer);
- if (ch->retry++ < 3)
- ctcm_chx_restart(fi, event, arg);
- else {
- fsm_newstate(fi, CTC_STATE_RXERR);
- fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
- }
- } else {
- CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
- "%s(%s): %s in %s", CTCM_FUNTAIL, ch->id,
- ctc_ch_event_names[event], fsm_getstate_str(fi));
- dev_warn(&dev->dev,
- "Initialization failed with RX/TX init handshake "
- "error %s\n", ctc_ch_event_names[event]);
- }
- }
- /**
- * Notify device statemachine if we gave up initialization
- * of RX channel.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcm_chx_rxinitfail(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
- "%s(%s): RX %s busy, init. fail",
- CTCM_FUNTAIL, dev->name, ch->id);
- fsm_newstate(fi, CTC_STATE_RXERR);
- fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
- }
- /**
- * Handle RX Unit check remote reset (remote disconnected)
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcm_chx_rxdisc(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct channel *ch2;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
- "%s: %s: remote disconnect - re-init ...",
- CTCM_FUNTAIL, dev->name);
- fsm_deltimer(&ch->timer);
- /*
- * Notify device statemachine
- */
- fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
- fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
- fsm_newstate(fi, CTC_STATE_DTERM);
- ch2 = priv->channel[CTCM_WRITE];
- fsm_newstate(ch2->fsm, CTC_STATE_DTERM);
- ccw_device_halt(ch->cdev, (unsigned long)ch);
- ccw_device_halt(ch2->cdev, (unsigned long)ch2);
- }
- /**
- * Handle error during TX channel initialization.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcm_chx_txiniterr(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- if (event == CTC_EVENT_TIMER) {
- fsm_deltimer(&ch->timer);
- if (ch->retry++ < 3)
- ctcm_chx_restart(fi, event, arg);
- else {
- fsm_newstate(fi, CTC_STATE_TXERR);
- fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
- }
- } else {
- CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
- "%s(%s): %s in %s", CTCM_FUNTAIL, ch->id,
- ctc_ch_event_names[event], fsm_getstate_str(fi));
- dev_warn(&dev->dev,
- "Initialization failed with RX/TX init handshake "
- "error %s\n", ctc_ch_event_names[event]);
- }
- }
- /**
- * Handle TX timeout by retrying operation.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcm_chx_txretry(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- struct sk_buff *skb;
- CTCM_PR_DEBUG("Enter: %s: cp=%i ch=0x%p id=%s\n",
- __func__, smp_processor_id(), ch, ch->id);
- fsm_deltimer(&ch->timer);
- if (ch->retry++ > 3) {
- struct mpc_group *gptr = priv->mpcg;
- CTCM_DBF_TEXT_(TRACE, CTC_DBF_INFO,
- "%s: %s: retries exceeded",
- CTCM_FUNTAIL, ch->id);
- fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
- /* call restart if not MPC or if MPC and mpcg fsm is ready.
- use gptr as mpc indicator */
- if (!(gptr && (fsm_getstate(gptr->fsm) != MPCG_STATE_READY)))
- ctcm_chx_restart(fi, event, arg);
- goto done;
- }
- CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
- "%s : %s: retry %d",
- CTCM_FUNTAIL, ch->id, ch->retry);
- skb = skb_peek(&ch->io_queue);
- if (skb) {
- int rc = 0;
- unsigned long saveflags = 0;
- clear_normalized_cda(&ch->ccw[4]);
- ch->ccw[4].count = skb->len;
- if (set_normalized_cda(&ch->ccw[4], skb->data)) {
- CTCM_DBF_TEXT_(TRACE, CTC_DBF_INFO,
- "%s: %s: IDAL alloc failed",
- CTCM_FUNTAIL, ch->id);
- fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
- ctcm_chx_restart(fi, event, arg);
- goto done;
- }
- fsm_addtimer(&ch->timer, 1000, CTC_EVENT_TIMER, ch);
- if (event == CTC_EVENT_TIMER) /* for TIMER not yet locked */
- spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
- /* Such conditional locking is a known problem for
- * sparse because its undeterministic in static view.
- * Warnings should be ignored here. */
- if (do_debug_ccw)
- ctcmpc_dumpit((char *)&ch->ccw[3],
- sizeof(struct ccw1) * 3);
- rc = ccw_device_start(ch->cdev, &ch->ccw[3],
- (unsigned long)ch, 0xff, 0);
- if (event == CTC_EVENT_TIMER)
- spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev),
- saveflags);
- if (rc != 0) {
- fsm_deltimer(&ch->timer);
- ctcm_ccw_check_rc(ch, rc, "TX in chx_txretry");
- ctcm_purge_skb_queue(&ch->io_queue);
- }
- }
- done:
- return;
- }
- /**
- * Handle fatal errors during an I/O command.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcm_chx_iofatal(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- int rd = CHANNEL_DIRECTION(ch->flags);
- fsm_deltimer(&ch->timer);
- CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
- "%s: %s: %s unrecoverable channel error",
- CTCM_FUNTAIL, ch->id, rd == CTCM_READ ? "RX" : "TX");
- if (IS_MPC(ch)) {
- priv->stats.tx_dropped++;
- priv->stats.tx_errors++;
- }
- if (rd == CTCM_READ) {
- fsm_newstate(fi, CTC_STATE_RXERR);
- fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
- } else {
- fsm_newstate(fi, CTC_STATE_TXERR);
- fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
- }
- }
- /*
- * The ctcm statemachine for a channel.
- */
- const fsm_node ch_fsm[] = {
- { CTC_STATE_STOPPED, CTC_EVENT_STOP, ctcm_action_nop },
- { CTC_STATE_STOPPED, CTC_EVENT_START, ctcm_chx_start },
- { CTC_STATE_STOPPED, CTC_EVENT_FINSTAT, ctcm_action_nop },
- { CTC_STATE_STOPPED, CTC_EVENT_MC_FAIL, ctcm_action_nop },
- { CTC_STATE_NOTOP, CTC_EVENT_STOP, ctcm_chx_stop },
- { CTC_STATE_NOTOP, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_NOTOP, CTC_EVENT_FINSTAT, ctcm_action_nop },
- { CTC_STATE_NOTOP, CTC_EVENT_MC_FAIL, ctcm_action_nop },
- { CTC_STATE_NOTOP, CTC_EVENT_MC_GOOD, ctcm_chx_start },
- { CTC_STATE_STARTWAIT, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_STARTWAIT, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_STARTWAIT, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
- { CTC_STATE_STARTWAIT, CTC_EVENT_TIMER, ctcm_chx_setuperr },
- { CTC_STATE_STARTWAIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_STARTWAIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_STARTRETRY, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_STARTRETRY, CTC_EVENT_TIMER, ctcm_chx_setmode },
- { CTC_STATE_STARTRETRY, CTC_EVENT_FINSTAT, ctcm_action_nop },
- { CTC_STATE_STARTRETRY, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_FINSTAT, chx_firstio },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_TIMER, ctcm_chx_setmode },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_RXINIT, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_RXINIT, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_RXINIT, CTC_EVENT_FINSTAT, chx_rxidle },
- { CTC_STATE_RXINIT, CTC_EVENT_UC_RCRESET, ctcm_chx_rxiniterr },
- { CTC_STATE_RXINIT, CTC_EVENT_UC_RSRESET, ctcm_chx_rxiniterr },
- { CTC_STATE_RXINIT, CTC_EVENT_TIMER, ctcm_chx_rxiniterr },
- { CTC_STATE_RXINIT, CTC_EVENT_ATTNBUSY, ctcm_chx_rxinitfail },
- { CTC_STATE_RXINIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_RXINIT, CTC_EVENT_UC_ZERO, chx_firstio },
- { CTC_STATE_RXINIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_RXIDLE, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_RXIDLE, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_RXIDLE, CTC_EVENT_FINSTAT, chx_rx },
- { CTC_STATE_RXIDLE, CTC_EVENT_UC_RCRESET, ctcm_chx_rxdisc },
- { CTC_STATE_RXIDLE, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_RXIDLE, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_RXIDLE, CTC_EVENT_UC_ZERO, chx_rx },
- { CTC_STATE_TXINIT, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_TXINIT, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_TXINIT, CTC_EVENT_FINSTAT, ctcm_chx_txidle },
- { CTC_STATE_TXINIT, CTC_EVENT_UC_RCRESET, ctcm_chx_txiniterr },
- { CTC_STATE_TXINIT, CTC_EVENT_UC_RSRESET, ctcm_chx_txiniterr },
- { CTC_STATE_TXINIT, CTC_EVENT_TIMER, ctcm_chx_txiniterr },
- { CTC_STATE_TXINIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_TXINIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_TXIDLE, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_TXIDLE, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_TXIDLE, CTC_EVENT_FINSTAT, chx_firstio },
- { CTC_STATE_TXIDLE, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
- { CTC_STATE_TXIDLE, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
- { CTC_STATE_TXIDLE, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_TXIDLE, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_TERM, CTC_EVENT_STOP, ctcm_action_nop },
- { CTC_STATE_TERM, CTC_EVENT_START, ctcm_chx_restart },
- { CTC_STATE_TERM, CTC_EVENT_FINSTAT, ctcm_chx_stopped },
- { CTC_STATE_TERM, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
- { CTC_STATE_TERM, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
- { CTC_STATE_TERM, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_DTERM, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_DTERM, CTC_EVENT_START, ctcm_chx_restart },
- { CTC_STATE_DTERM, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
- { CTC_STATE_DTERM, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
- { CTC_STATE_DTERM, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
- { CTC_STATE_DTERM, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_TX, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_TX, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_TX, CTC_EVENT_FINSTAT, chx_txdone },
- { CTC_STATE_TX, CTC_EVENT_UC_RCRESET, ctcm_chx_txretry },
- { CTC_STATE_TX, CTC_EVENT_UC_RSRESET, ctcm_chx_txretry },
- { CTC_STATE_TX, CTC_EVENT_TIMER, ctcm_chx_txretry },
- { CTC_STATE_TX, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_TX, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_RXERR, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_TXERR, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_TXERR, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_RXERR, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- };
- int ch_fsm_len = ARRAY_SIZE(ch_fsm);
- /*
- * MPC actions for mpc channel statemachine
- * handling of MPC protocol requires extra
- * statemachine and actions which are prefixed ctcmpc_ .
- * The ctc_ch_states and ctc_ch_state_names,
- * ctc_ch_events and ctc_ch_event_names share the ctcm definitions
- * which are expanded by some elements.
- */
- /*
- * Actions for mpc channel statemachine.
- */
- /**
- * Normal data has been send. Free the corresponding
- * skb (it's in io_queue), reset dev->tbusy and
- * revert to idle state.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcmpc_chx_txdone(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- struct mpc_group *grp = priv->mpcg;
- struct sk_buff *skb;
- int first = 1;
- int i;
- __u32 data_space;
- unsigned long duration;
- struct sk_buff *peekskb;
- int rc;
- struct th_header *header;
- struct pdu *p_header;
- unsigned long done_stamp = jiffies;
- CTCM_PR_DEBUG("Enter %s: %s cp:%i\n",
- __func__, dev->name, smp_processor_id());
- duration = done_stamp - ch->prof.send_stamp;
- if (duration > ch->prof.tx_time)
- ch->prof.tx_time = duration;
- if (ch->irb->scsw.cmd.count != 0)
- CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
- "%s(%s): TX not complete, remaining %d bytes",
- CTCM_FUNTAIL, dev->name, ch->irb->scsw.cmd.count);
- fsm_deltimer(&ch->timer);
- while ((skb = skb_dequeue(&ch->io_queue))) {
- priv->stats.tx_packets++;
- priv->stats.tx_bytes += skb->len - TH_HEADER_LENGTH;
- if (first) {
- priv->stats.tx_bytes += 2;
- first = 0;
- }
- atomic_dec(&skb->users);
- dev_kfree_skb_irq(skb);
- }
- spin_lock(&ch->collect_lock);
- clear_normalized_cda(&ch->ccw[4]);
- if ((ch->collect_len <= 0) || (grp->in_sweep != 0)) {
- spin_unlock(&ch->collect_lock);
- fsm_newstate(fi, CTC_STATE_TXIDLE);
- goto done;
- }
- if (ctcm_checkalloc_buffer(ch)) {
- spin_unlock(&ch->collect_lock);
- goto done;
- }
- ch->trans_skb->data = ch->trans_skb_data;
- skb_reset_tail_pointer(ch->trans_skb);
- ch->trans_skb->len = 0;
- if (ch->prof.maxmulti < (ch->collect_len + TH_HEADER_LENGTH))
- ch->prof.maxmulti = ch->collect_len + TH_HEADER_LENGTH;
- if (ch->prof.maxcqueue < skb_queue_len(&ch->collect_queue))
- ch->prof.maxcqueue = skb_queue_len(&ch->collect_queue);
- i = 0;
- p_header = NULL;
- data_space = grp->group_max_buflen - TH_HEADER_LENGTH;
- CTCM_PR_DBGDATA("%s: building trans_skb from collect_q"
- " data_space:%04x\n",
- __func__, data_space);
- while ((skb = skb_dequeue(&ch->collect_queue))) {
- memcpy(skb_put(ch->trans_skb, skb->len), skb->data, skb->len);
- p_header = (struct pdu *)
- (skb_tail_pointer(ch->trans_skb) - skb->len);
- p_header->pdu_flag = 0x00;
- if (skb->protocol == ntohs(ETH_P_SNAP))
- p_header->pdu_flag |= 0x60;
- else
- p_header->pdu_flag |= 0x20;
- CTCM_PR_DBGDATA("%s: trans_skb len:%04x \n",
- __func__, ch->trans_skb->len);
- CTCM_PR_DBGDATA("%s: pdu header and data for up"
- " to 32 bytes sent to vtam\n", __func__);
- CTCM_D3_DUMP((char *)p_header, min_t(int, skb->len, 32));
- ch->collect_len -= skb->len;
- data_space -= skb->len;
- priv->stats.tx_packets++;
- priv->stats.tx_bytes += skb->len;
- atomic_dec(&skb->users);
- dev_kfree_skb_any(skb);
- peekskb = skb_peek(&ch->collect_queue);
- if (peekskb->len > data_space)
- break;
- i++;
- }
- /* p_header points to the last one we handled */
- if (p_header)
- p_header->pdu_flag |= PDU_LAST; /*Say it's the last one*/
- header = kzalloc(TH_HEADER_LENGTH, gfp_type());
- if (!header) {
- spin_unlock(&ch->collect_lock);
- fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
- goto done;
- }
- header->th_ch_flag = TH_HAS_PDU; /* Normal data */
- ch->th_seq_num++;
- header->th_seq_num = ch->th_seq_num;
- CTCM_PR_DBGDATA("%s: ToVTAM_th_seq= %08x\n" ,
- __func__, ch->th_seq_num);
- memcpy(skb_push(ch->trans_skb, TH_HEADER_LENGTH), header,
- TH_HEADER_LENGTH); /* put the TH on the packet */
- kfree(header);
- CTCM_PR_DBGDATA("%s: trans_skb len:%04x \n",
- __func__, ch->trans_skb->len);
- CTCM_PR_DBGDATA("%s: up-to-50 bytes of trans_skb "
- "data to vtam from collect_q\n", __func__);
- CTCM_D3_DUMP((char *)ch->trans_skb->data,
- min_t(int, ch->trans_skb->len, 50));
- spin_unlock(&ch->collect_lock);
- clear_normalized_cda(&ch->ccw[1]);
- CTCM_PR_DBGDATA("ccwcda=0x%p data=0x%p\n",
- (void *)(unsigned long)ch->ccw[1].cda,
- ch->trans_skb->data);
- ch->ccw[1].count = ch->max_bufsize;
- if (set_normalized_cda(&ch->ccw[1], ch->trans_skb->data)) {
- dev_kfree_skb_any(ch->trans_skb);
- ch->trans_skb = NULL;
- CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR,
- "%s: %s: IDAL alloc failed",
- CTCM_FUNTAIL, ch->id);
- fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
- return;
- }
- CTCM_PR_DBGDATA("ccwcda=0x%p data=0x%p\n",
- (void *)(unsigned long)ch->ccw[1].cda,
- ch->trans_skb->data);
- ch->ccw[1].count = ch->trans_skb->len;
- fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
- ch->prof.send_stamp = jiffies;
- if (do_debug_ccw)
- ctcmpc_dumpit((char *)&ch->ccw[0], sizeof(struct ccw1) * 3);
- rc = ccw_device_start(ch->cdev, &ch->ccw[0],
- (unsigned long)ch, 0xff, 0);
- ch->prof.doios_multi++;
- if (rc != 0) {
- priv->stats.tx_dropped += i;
- priv->stats.tx_errors += i;
- fsm_deltimer(&ch->timer);
- ctcm_ccw_check_rc(ch, rc, "chained TX");
- }
- done:
- ctcm_clear_busy(dev);
- return;
- }
- /**
- * Got normal data, check for sanity, queue it up, allocate new buffer
- * trigger bottom half, and initiate next read.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcmpc_chx_rx(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- struct mpc_group *grp = priv->mpcg;
- struct sk_buff *skb = ch->trans_skb;
- struct sk_buff *new_skb;
- unsigned long saveflags = 0; /* avoids compiler warning */
- int len = ch->max_bufsize - ch->irb->scsw.cmd.count;
- CTCM_PR_DEBUG("%s: %s: cp:%i %s maxbuf : %04x, len: %04x\n",
- CTCM_FUNTAIL, dev->name, smp_processor_id(),
- ch->id, ch->max_bufsize, len);
- fsm_deltimer(&ch->timer);
- if (skb == NULL) {
- CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
- "%s(%s): TRANS_SKB = NULL",
- CTCM_FUNTAIL, dev->name);
- goto again;
- }
- if (len < TH_HEADER_LENGTH) {
- CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
- "%s(%s): packet length %d to short",
- CTCM_FUNTAIL, dev->name, len);
- priv->stats.rx_dropped++;
- priv->stats.rx_length_errors++;
- } else {
- /* must have valid th header or game over */
- __u32 block_len = len;
- len = TH_HEADER_LENGTH + XID2_LENGTH + 4;
- new_skb = __dev_alloc_skb(ch->max_bufsize, GFP_ATOMIC);
- if (new_skb == NULL) {
- CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
- "%s(%d): skb allocation failed",
- CTCM_FUNTAIL, dev->name);
- fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
- goto again;
- }
- switch (fsm_getstate(grp->fsm)) {
- case MPCG_STATE_RESET:
- case MPCG_STATE_INOP:
- dev_kfree_skb_any(new_skb);
- break;
- case MPCG_STATE_FLOWC:
- case MPCG_STATE_READY:
- memcpy(skb_put(new_skb, block_len),
- skb->data, block_len);
- skb_queue_tail(&ch->io_queue, new_skb);
- tasklet_schedule(&ch->ch_tasklet);
- break;
- default:
- memcpy(skb_put(new_skb, len), skb->data, len);
- skb_queue_tail(&ch->io_queue, new_skb);
- tasklet_hi_schedule(&ch->ch_tasklet);
- break;
- }
- }
- again:
- switch (fsm_getstate(grp->fsm)) {
- int rc, dolock;
- case MPCG_STATE_FLOWC:
- case MPCG_STATE_READY:
- if (ctcm_checkalloc_buffer(ch))
- break;
- ch->trans_skb->data = ch->trans_skb_data;
- skb_reset_tail_pointer(ch->trans_skb);
- ch->trans_skb->len = 0;
- ch->ccw[1].count = ch->max_bufsize;
- if (do_debug_ccw)
- ctcmpc_dumpit((char *)&ch->ccw[0],
- sizeof(struct ccw1) * 3);
- dolock = !in_irq();
- if (dolock)
- spin_lock_irqsave(
- get_ccwdev_lock(ch->cdev), saveflags);
- rc = ccw_device_start(ch->cdev, &ch->ccw[0],
- (unsigned long)ch, 0xff, 0);
- if (dolock) /* see remark about conditional locking */
- spin_unlock_irqrestore(
- get_ccwdev_lock(ch->cdev), saveflags);
- if (rc != 0)
- ctcm_ccw_check_rc(ch, rc, "normal RX");
- default:
- break;
- }
- CTCM_PR_DEBUG("Exit %s: %s, ch=0x%p, id=%s\n",
- __func__, dev->name, ch, ch->id);
- }
- /**
- * Initialize connection by sending a __u16 of value 0.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- static void ctcmpc_chx_firstio(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- struct mpc_group *gptr = priv->mpcg;
- CTCM_PR_DEBUG("Enter %s: id=%s, ch=0x%p\n",
- __func__, ch->id, ch);
- CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_INFO,
- "%s: %s: chstate:%i, grpstate:%i, prot:%i\n",
- CTCM_FUNTAIL, ch->id, fsm_getstate(fi),
- fsm_getstate(gptr->fsm), ch->protocol);
- if (fsm_getstate(fi) == CTC_STATE_TXIDLE)
- MPC_DBF_DEV_NAME(TRACE, dev, "remote side issued READ? ");
- fsm_deltimer(&ch->timer);
- if (ctcm_checkalloc_buffer(ch))
- goto done;
- switch (fsm_getstate(fi)) {
- case CTC_STATE_STARTRETRY:
- case CTC_STATE_SETUPWAIT:
- if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
- ctcmpc_chx_rxidle(fi, event, arg);
- } else {
- fsm_newstate(fi, CTC_STATE_TXIDLE);
- fsm_event(priv->fsm, DEV_EVENT_TXUP, dev);
- }
- goto done;
- default:
- break;
- }
- fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == CTCM_READ)
- ? CTC_STATE_RXINIT : CTC_STATE_TXINIT);
- done:
- CTCM_PR_DEBUG("Exit %s: id=%s, ch=0x%p\n",
- __func__, ch->id, ch);
- return;
- }
- /**
- * Got initial data, check it. If OK,
- * notify device statemachine that we are up and
- * running.
- *
- * fi An instance of a channel statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from channel * upon call.
- */
- void ctcmpc_chx_rxidle(fsm_instance *fi, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- struct mpc_group *grp = priv->mpcg;
- int rc;
- unsigned long saveflags = 0; /* avoids compiler warning */
- fsm_deltimer(&ch->timer);
- CTCM_PR_DEBUG("%s: %s: %s: cp:%i, chstate:%i grpstate:%i\n",
- __func__, ch->id, dev->name, smp_processor_id(),
- fsm_getstate(fi), fsm_getstate(grp->fsm));
- fsm_newstate(fi, CTC_STATE_RXIDLE);
- /* XID processing complete */
- switch (fsm_getstate(grp->fsm)) {
- case MPCG_STATE_FLOWC:
- case MPCG_STATE_READY:
- if (ctcm_checkalloc_buffer(ch))
- goto done;
- ch->trans_skb->data = ch->trans_skb_data;
- skb_reset_tail_pointer(ch->trans_skb);
- ch->trans_skb->len = 0;
- ch->ccw[1].count = ch->max_bufsize;
- CTCM_CCW_DUMP((char *)&ch->ccw[0], sizeof(struct ccw1) * 3);
- if (event == CTC_EVENT_START)
- /* see remark about conditional locking */
- spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
- rc = ccw_device_start(ch->cdev, &ch->ccw[0],
- (unsigned long)ch, 0xff, 0);
- if (event == CTC_EVENT_START)
- spin_unlock_irqrestore(
- get_ccwdev_lock(ch->cdev), saveflags);
- if (rc != 0) {
- fsm_newstate(fi, CTC_STATE_RXINIT);
- ctcm_ccw_check_rc(ch, rc, "initial RX");
- goto done;
- }
- break;
- default:
- break;
- }
- fsm_event(priv->fsm, DEV_EVENT_RXUP, dev);
- done:
- return;
- }
- /*
- * ctcmpc channel FSM action
- * called from several points in ctcmpc_ch_fsm
- * ctcmpc only
- */
- static void ctcmpc_chx_attn(fsm_instance *fsm, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- struct mpc_group *grp = priv->mpcg;
- CTCM_PR_DEBUG("%s(%s): %s(ch=0x%p), cp=%i, ChStat:%s, GrpStat:%s\n",
- __func__, dev->name, ch->id, ch, smp_processor_id(),
- fsm_getstate_str(ch->fsm), fsm_getstate_str(grp->fsm));
- switch (fsm_getstate(grp->fsm)) {
- case MPCG_STATE_XID2INITW:
- /* ok..start yside xid exchanges */
- if (!ch->in_mpcgroup)
- break;
- if (fsm_getstate(ch->fsm) == CH_XID0_PENDING) {
- fsm_deltimer(&grp->timer);
- fsm_addtimer(&grp->timer,
- MPC_XID_TIMEOUT_VALUE,
- MPCG_EVENT_TIMER, dev);
- fsm_event(grp->fsm, MPCG_EVENT_XID0DO, ch);
- } else if (fsm_getstate(ch->fsm) < CH_XID7_PENDING1)
- /* attn rcvd before xid0 processed via bh */
- fsm_newstate(ch->fsm, CH_XID7_PENDING1);
- break;
- case MPCG_STATE_XID2INITX:
- case MPCG_STATE_XID0IOWAIT:
- case MPCG_STATE_XID0IOWAIX:
- /* attn rcvd before xid0 processed on ch
- but mid-xid0 processing for group */
- if (fsm_getstate(ch->fsm) < CH_XID7_PENDING1)
- fsm_newstate(ch->fsm, CH_XID7_PENDING1);
- break;
- case MPCG_STATE_XID7INITW:
- case MPCG_STATE_XID7INITX:
- case MPCG_STATE_XID7INITI:
- case MPCG_STATE_XID7INITZ:
- switch (fsm_getstate(ch->fsm)) {
- case CH_XID7_PENDING:
- fsm_newstate(ch->fsm, CH_XID7_PENDING1);
- break;
- case CH_XID7_PENDING2:
- fsm_newstate(ch->fsm, CH_XID7_PENDING3);
- break;
- }
- fsm_event(grp->fsm, MPCG_EVENT_XID7DONE, dev);
- break;
- }
- return;
- }
- /*
- * ctcmpc channel FSM action
- * called from one point in ctcmpc_ch_fsm
- * ctcmpc only
- */
- static void ctcmpc_chx_attnbusy(fsm_instance *fsm, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- struct mpc_group *grp = priv->mpcg;
- CTCM_PR_DEBUG("%s(%s): %s\n ChState:%s GrpState:%s\n",
- __func__, dev->name, ch->id,
- fsm_getstate_str(ch->fsm), fsm_getstate_str(grp->fsm));
- fsm_deltimer(&ch->timer);
- switch (fsm_getstate(grp->fsm)) {
- case MPCG_STATE_XID0IOWAIT:
- /* vtam wants to be primary.start yside xid exchanges*/
- /* only receive one attn-busy at a time so must not */
- /* change state each time */
- grp->changed_side = 1;
- fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);
- break;
- case MPCG_STATE_XID2INITW:
- if (grp->changed_side == 1) {
- grp->changed_side = 2;
- break;
- }
- /* process began via call to establish_conn */
- /* so must report failure instead of reverting */
- /* back to ready-for-xid passive state */
- if (grp->estconnfunc)
- goto done;
- /* this attnbusy is NOT the result of xside xid */
- /* collisions so yside must have been triggered */
- /* by an ATTN that was not intended to start XID */
- /* processing. Revert back to ready-for-xid and */
- /* wait for ATTN interrupt to signal xid start */
- if (fsm_getstate(ch->fsm) == CH_XID0_INPROGRESS) {
- fsm_newstate(ch->fsm, CH_XID0_PENDING) ;
- fsm_deltimer(&grp->timer);
- goto done;
- }
- fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
- goto done;
- case MPCG_STATE_XID2INITX:
- /* XID2 was received before ATTN Busy for second
- channel.Send yside xid for second channel.
- */
- if (grp->changed_side == 1) {
- grp->changed_side = 2;
- break;
- }
- case MPCG_STATE_XID0IOWAIX:
- case MPCG_STATE_XID7INITW:
- case MPCG_STATE_XID7INITX:
- case MPCG_STATE_XID7INITI:
- case MPCG_STATE_XID7INITZ:
- default:
- /* multiple attn-busy indicates too out-of-sync */
- /* and they are certainly not being received as part */
- /* of valid mpc group negotiations.. */
- fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
- goto done;
- }
- if (grp->changed_side == 1) {
- fsm_deltimer(&grp->timer);
- fsm_addtimer(&grp->timer, MPC_XID_TIMEOUT_VALUE,
- MPCG_EVENT_TIMER, dev);
- }
- if (ch->in_mpcgroup)
- fsm_event(grp->fsm, MPCG_EVENT_XID0DO, ch);
- else
- CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
- "%s(%s): channel %s not added to group",
- CTCM_FUNTAIL, dev->name, ch->id);
- done:
- return;
- }
- /*
- * ctcmpc channel FSM action
- * called from several points in ctcmpc_ch_fsm
- * ctcmpc only
- */
- static void ctcmpc_chx_resend(fsm_instance *fsm, int event, void *arg)
- {
- struct channel *ch = arg;
- struct net_device *dev = ch->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- struct mpc_group *grp = priv->mpcg;
- fsm_event(grp->fsm, MPCG_EVENT_XID0DO, ch);
- return;
- }
- /*
- * ctcmpc channel FSM action
- * called from several points in ctcmpc_ch_fsm
- * ctcmpc only
- */
- static void ctcmpc_chx_send_sweep(fsm_instance *fsm, int event, void *arg)
- {
- struct channel *ach = arg;
- struct net_device *dev = ach->netdev;
- struct ctcm_priv *priv = dev->ml_priv;
- struct mpc_group *grp = priv->mpcg;
- struct channel *wch = priv->channel[CTCM_WRITE];
- struct channel *rch = priv->channel[CTCM_READ];
- struct sk_buff *skb;
- struct th_sweep *header;
- int rc = 0;
- unsigned long saveflags = 0;
- CTCM_PR_DEBUG("ctcmpc enter: %s(): cp=%i ch=0x%p id=%s\n",
- __func__, smp_processor_id(), ach, ach->id);
- if (grp->in_sweep == 0)
- goto done;
- CTCM_PR_DBGDATA("%s: 1: ToVTAM_th_seq= %08x\n" ,
- __func__, wch->th_seq_num);
- CTCM_PR_DBGDATA("%s: 1: FromVTAM_th_seq= %08x\n" ,
- __func__, rch->th_seq_num);
- if (fsm_getstate(wch->fsm) != CTC_STATE_TXIDLE) {
- /* give the previous IO time to complete */
- fsm_addtimer(&wch->sweep_timer,
- 200, CTC_EVENT_RSWEEP_TIMER, wch);
- goto done;
- }
- skb = skb_dequeue(&wch->sweep_queue);
- if (!skb)
- goto done;
- if (set_normalized_cda(&wch->ccw[4], skb->data)) {
- grp->in_sweep = 0;
- ctcm_clear_busy_do(dev);
- dev_kfree_skb_any(skb);
- fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
- goto done;
- } else {
- atomic_inc(&skb->users);
- skb_queue_tail(&wch->io_queue, skb);
- }
- /* send out the sweep */
- wch->ccw[4].count = skb->len;
- header = (struct th_sweep *)skb->data;
- switch (header->th.th_ch_flag) {
- case TH_SWEEP_REQ:
- grp->sweep_req_pend_num--;
- break;
- case TH_SWEEP_RESP:
- grp->sweep_rsp_pend_num--;
- break;
- }
- header->sw.th_last_seq = wch->th_seq_num;
- CTCM_CCW_DUMP((char *)&wch->ccw[3], sizeof(struct ccw1) * 3);
- CTCM_PR_DBGDATA("%s: sweep packet\n", __func__);
- CTCM_D3_DUMP((char *)header, TH_SWEEP_LENGTH);
- fsm_addtimer(&wch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, wch);
- fsm_newstate(wch->fsm, CTC_STATE_TX);
- spin_lock_irqsave(get_ccwdev_lock(wch->cdev), saveflags);
- wch->prof.send_stamp = jiffies;
- rc = ccw_device_start(wch->cdev, &wch->ccw[3],
- (unsigned long) wch, 0xff, 0);
- spin_unlock_irqrestore(get_ccwdev_lock(wch->cdev), saveflags);
- if ((grp->sweep_req_pend_num == 0) &&
- (grp->sweep_rsp_pend_num == 0)) {
- grp->in_sweep = 0;
- rch->th_seq_num = 0x00;
- wch->th_seq_num = 0x00;
- ctcm_clear_busy_do(dev);
- }
- CTCM_PR_DBGDATA("%s: To-/From-VTAM_th_seq = %08x/%08x\n" ,
- __func__, wch->th_seq_num, rch->th_seq_num);
- if (rc != 0)
- ctcm_ccw_check_rc(wch, rc, "send sweep");
- done:
- return;
- }
- /*
- * The ctcmpc statemachine for a channel.
- */
- const fsm_node ctcmpc_ch_fsm[] = {
- { CTC_STATE_STOPPED, CTC_EVENT_STOP, ctcm_action_nop },
- { CTC_STATE_STOPPED, CTC_EVENT_START, ctcm_chx_start },
- { CTC_STATE_STOPPED, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_STOPPED, CTC_EVENT_FINSTAT, ctcm_action_nop },
- { CTC_STATE_STOPPED, CTC_EVENT_MC_FAIL, ctcm_action_nop },
- { CTC_STATE_NOTOP, CTC_EVENT_STOP, ctcm_chx_stop },
- { CTC_STATE_NOTOP, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_NOTOP, CTC_EVENT_FINSTAT, ctcm_action_nop },
- { CTC_STATE_NOTOP, CTC_EVENT_MC_FAIL, ctcm_action_nop },
- { CTC_STATE_NOTOP, CTC_EVENT_MC_GOOD, ctcm_chx_start },
- { CTC_STATE_NOTOP, CTC_EVENT_UC_RCRESET, ctcm_chx_stop },
- { CTC_STATE_NOTOP, CTC_EVENT_UC_RSRESET, ctcm_chx_stop },
- { CTC_STATE_NOTOP, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_STARTWAIT, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_STARTWAIT, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_STARTWAIT, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
- { CTC_STATE_STARTWAIT, CTC_EVENT_TIMER, ctcm_chx_setuperr },
- { CTC_STATE_STARTWAIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_STARTWAIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_STARTRETRY, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_STARTRETRY, CTC_EVENT_TIMER, ctcm_chx_setmode },
- { CTC_STATE_STARTRETRY, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
- { CTC_STATE_STARTRETRY, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_STARTRETRY, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_FINSTAT, ctcmpc_chx_firstio },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_TIMER, ctcm_chx_setmode },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_SETUPWAIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_RXINIT, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_RXINIT, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_RXINIT, CTC_EVENT_FINSTAT, ctcmpc_chx_rxidle },
- { CTC_STATE_RXINIT, CTC_EVENT_UC_RCRESET, ctcm_chx_rxiniterr },
- { CTC_STATE_RXINIT, CTC_EVENT_UC_RSRESET, ctcm_chx_rxiniterr },
- { CTC_STATE_RXINIT, CTC_EVENT_TIMER, ctcm_chx_rxiniterr },
- { CTC_STATE_RXINIT, CTC_EVENT_ATTNBUSY, ctcm_chx_rxinitfail },
- { CTC_STATE_RXINIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_RXINIT, CTC_EVENT_UC_ZERO, ctcmpc_chx_firstio },
- { CTC_STATE_RXINIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CH_XID0_PENDING, CTC_EVENT_FINSTAT, ctcm_action_nop },
- { CH_XID0_PENDING, CTC_EVENT_ATTN, ctcmpc_chx_attn },
- { CH_XID0_PENDING, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CH_XID0_PENDING, CTC_EVENT_START, ctcm_action_nop },
- { CH_XID0_PENDING, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CH_XID0_PENDING, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CH_XID0_PENDING, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
- { CH_XID0_PENDING, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
- { CH_XID0_PENDING, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
- { CH_XID0_PENDING, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
- { CH_XID0_INPROGRESS, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
- { CH_XID0_INPROGRESS, CTC_EVENT_ATTN, ctcmpc_chx_attn },
- { CH_XID0_INPROGRESS, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CH_XID0_INPROGRESS, CTC_EVENT_START, ctcm_action_nop },
- { CH_XID0_INPROGRESS, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CH_XID0_INPROGRESS, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CH_XID0_INPROGRESS, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
- { CH_XID0_INPROGRESS, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
- { CH_XID0_INPROGRESS, CTC_EVENT_ATTNBUSY, ctcmpc_chx_attnbusy },
- { CH_XID0_INPROGRESS, CTC_EVENT_TIMER, ctcmpc_chx_resend },
- { CH_XID0_INPROGRESS, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
- { CH_XID7_PENDING, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
- { CH_XID7_PENDING, CTC_EVENT_ATTN, ctcmpc_chx_attn },
- { CH_XID7_PENDING, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CH_XID7_PENDING, CTC_EVENT_START, ctcm_action_nop },
- { CH_XID7_PENDING, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CH_XID7_PENDING, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CH_XID7_PENDING, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
- { CH_XID7_PENDING, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
- { CH_XID7_PENDING, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
- { CH_XID7_PENDING, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
- { CH_XID7_PENDING, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
- { CH_XID7_PENDING, CTC_EVENT_TIMER, ctcmpc_chx_resend },
- { CH_XID7_PENDING, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
- { CH_XID7_PENDING1, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
- { CH_XID7_PENDING1, CTC_EVENT_ATTN, ctcmpc_chx_attn },
- { CH_XID7_PENDING1, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CH_XID7_PENDING1, CTC_EVENT_START, ctcm_action_nop },
- { CH_XID7_PENDING1, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CH_XID7_PENDING1, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CH_XID7_PENDING1, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
- { CH_XID7_PENDING1, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
- { CH_XID7_PENDING1, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
- { CH_XID7_PENDING1, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
- { CH_XID7_PENDING1, CTC_EVENT_TIMER, ctcmpc_chx_resend },
- { CH_XID7_PENDING1, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
- { CH_XID7_PENDING2, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
- { CH_XID7_PENDING2, CTC_EVENT_ATTN, ctcmpc_chx_attn },
- { CH_XID7_PENDING2, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CH_XID7_PENDING2, CTC_EVENT_START, ctcm_action_nop },
- { CH_XID7_PENDING2, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CH_XID7_PENDING2, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CH_XID7_PENDING2, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
- { CH_XID7_PENDING2, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
- { CH_XID7_PENDING2, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
- { CH_XID7_PENDING2, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
- { CH_XID7_PENDING2, CTC_EVENT_TIMER, ctcmpc_chx_resend },
- { CH_XID7_PENDING2, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
- { CH_XID7_PENDING3, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
- { CH_XID7_PENDING3, CTC_EVENT_ATTN, ctcmpc_chx_attn },
- { CH_XID7_PENDING3, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CH_XID7_PENDING3, CTC_EVENT_START, ctcm_action_nop },
- { CH_XID7_PENDING3, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CH_XID7_PENDING3, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CH_XID7_PENDING3, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
- { CH_XID7_PENDING3, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
- { CH_XID7_PENDING3, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
- { CH_XID7_PENDING3, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
- { CH_XID7_PENDING3, CTC_EVENT_TIMER, ctcmpc_chx_resend },
- { CH_XID7_PENDING3, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
- { CH_XID7_PENDING4, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
- { CH_XID7_PENDING4, CTC_EVENT_ATTN, ctcmpc_chx_attn },
- { CH_XID7_PENDING4, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CH_XID7_PENDING4, CTC_EVENT_START, ctcm_action_nop },
- { CH_XID7_PENDING4, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CH_XID7_PENDING4, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CH_XID7_PENDING4, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
- { CH_XID7_PENDING4, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
- { CH_XID7_PENDING4, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
- { CH_XID7_PENDING4, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
- { CH_XID7_PENDING4, CTC_EVENT_TIMER, ctcmpc_chx_resend },
- { CH_XID7_PENDING4, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
- { CTC_STATE_RXIDLE, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_RXIDLE, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_RXIDLE, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
- { CTC_STATE_RXIDLE, CTC_EVENT_UC_RCRESET, ctcm_chx_rxdisc },
- { CTC_STATE_RXIDLE, CTC_EVENT_UC_RSRESET, ctcm_chx_fail },
- { CTC_STATE_RXIDLE, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_RXIDLE, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_RXIDLE, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
- { CTC_STATE_TXINIT, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_TXINIT, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_TXINIT, CTC_EVENT_FINSTAT, ctcm_chx_txidle },
- { CTC_STATE_TXINIT, CTC_EVENT_UC_RCRESET, ctcm_chx_txiniterr },
- { CTC_STATE_TXINIT, CTC_EVENT_UC_RSRESET, ctcm_chx_txiniterr },
- { CTC_STATE_TXINIT, CTC_EVENT_TIMER, ctcm_chx_txiniterr },
- { CTC_STATE_TXINIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_TXINIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_TXINIT, CTC_EVENT_RSWEEP_TIMER, ctcmpc_chx_send_sweep },
- { CTC_STATE_TXIDLE, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_TXIDLE, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_TXIDLE, CTC_EVENT_FINSTAT, ctcmpc_chx_firstio },
- { CTC_STATE_TXIDLE, CTC_EVENT_UC_RCRESET, ctcm_chx_fail },
- { CTC_STATE_TXIDLE, CTC_EVENT_UC_RSRESET, ctcm_chx_fail },
- { CTC_STATE_TXIDLE, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_TXIDLE, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_TXIDLE, CTC_EVENT_RSWEEP_TIMER, ctcmpc_chx_send_sweep },
- { CTC_STATE_TERM, CTC_EVENT_STOP, ctcm_action_nop },
- { CTC_STATE_TERM, CTC_EVENT_START, ctcm_chx_restart },
- { CTC_STATE_TERM, CTC_EVENT_FINSTAT, ctcm_chx_stopped },
- { CTC_STATE_TERM, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
- { CTC_STATE_TERM, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
- { CTC_STATE_TERM, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_TERM, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
- { CTC_STATE_TERM, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_DTERM, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_DTERM, CTC_EVENT_START, ctcm_chx_restart },
- { CTC_STATE_DTERM, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
- { CTC_STATE_DTERM, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
- { CTC_STATE_DTERM, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
- { CTC_STATE_DTERM, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_DTERM, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_TX, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_TX, CTC_EVENT_START, ctcm_action_nop },
- { CTC_STATE_TX, CTC_EVENT_FINSTAT, ctcmpc_chx_txdone },
- { CTC_STATE_TX, CTC_EVENT_UC_RCRESET, ctcm_chx_fail },
- { CTC_STATE_TX, CTC_EVENT_UC_RSRESET, ctcm_chx_fail },
- { CTC_STATE_TX, CTC_EVENT_TIMER, ctcm_chx_txretry },
- { CTC_STATE_TX, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_TX, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_TX, CTC_EVENT_RSWEEP_TIMER, ctcmpc_chx_send_sweep },
- { CTC_STATE_TX, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
- { CTC_STATE_RXERR, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_TXERR, CTC_EVENT_STOP, ctcm_chx_haltio },
- { CTC_STATE_TXERR, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
- { CTC_STATE_TXERR, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- { CTC_STATE_RXERR, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
- };
- int mpc_ch_fsm_len = ARRAY_SIZE(ctcmpc_ch_fsm);
- /*
- * Actions for interface - statemachine.
- */
- /**
- * Startup channels by sending CTC_EVENT_START to each channel.
- *
- * fi An instance of an interface statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from struct net_device * upon call.
- */
- static void dev_action_start(fsm_instance *fi, int event, void *arg)
- {
- struct net_device *dev = arg;
- struct ctcm_priv *priv = dev->ml_priv;
- int direction;
- CTCMY_DBF_DEV_NAME(SETUP, dev, "");
- fsm_deltimer(&priv->restart_timer);
- fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
- if (IS_MPC(priv))
- priv->mpcg->channels_terminating = 0;
- for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
- struct channel *ch = priv->channel[direction];
- fsm_event(ch->fsm, CTC_EVENT_START, ch);
- }
- }
- /**
- * Shutdown channels by sending CTC_EVENT_STOP to each channel.
- *
- * fi An instance of an interface statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from struct net_device * upon call.
- */
- static void dev_action_stop(fsm_instance *fi, int event, void *arg)
- {
- int direction;
- struct net_device *dev = arg;
- struct ctcm_priv *priv = dev->ml_priv;
- CTCMY_DBF_DEV_NAME(SETUP, dev, "");
- fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
- for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
- struct channel *ch = priv->channel[direction];
- fsm_event(ch->fsm, CTC_EVENT_STOP, ch);
- ch->th_seq_num = 0x00;
- CTCM_PR_DEBUG("%s: CH_th_seq= %08x\n",
- __func__, ch->th_seq_num);
- }
- if (IS_MPC(priv))
- fsm_newstate(priv->mpcg->fsm, MPCG_STATE_RESET);
- }
- static void dev_action_restart(fsm_instance *fi, int event, void *arg)
- {
- int restart_timer;
- struct net_device *dev = arg;
- struct ctcm_priv *priv = dev->ml_priv;
- CTCMY_DBF_DEV_NAME(TRACE, dev, "");
- if (IS_MPC(priv)) {
- restart_timer = CTCM_TIME_1_SEC;
- } else {
- restart_timer = CTCM_TIME_5_SEC;
- }
- dev_info(&dev->dev, "Restarting device\n");
- dev_action_stop(fi, event, arg);
- fsm_event(priv->fsm, DEV_EVENT_STOP, dev);
- if (IS_MPC(priv))
- fsm_newstate(priv->mpcg->fsm, MPCG_STATE_RESET);
- /* going back into start sequence too quickly can */
- /* result in the other side becoming unreachable due */
- /* to sense reported when IO is aborted */
- fsm_addtimer(&priv->restart_timer, restart_timer,
- DEV_EVENT_START, dev);
- }
- /**
- * Called from channel statemachine
- * when a channel is up and running.
- *
- * fi An instance of an interface statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from struct net_device * upon call.
- */
- static void dev_action_chup(fsm_instance *fi, int event, void *arg)
- {
- struct net_device *dev = arg;
- struct ctcm_priv *priv = dev->ml_priv;
- int dev_stat = fsm_getstate(fi);
- CTCM_DBF_TEXT_(SETUP, CTC_DBF_NOTICE,
- "%s(%s): priv = %p [%d,%d]\n ", CTCM_FUNTAIL,
- dev->name, dev->ml_priv, dev_stat, event);
- switch (fsm_getstate(fi)) {
- case DEV_STATE_STARTWAIT_RXTX:
- if (event == DEV_EVENT_RXUP)
- fsm_newstate(fi, DEV_STATE_STARTWAIT_TX);
- else
- fsm_newstate(fi, DEV_STATE_STARTWAIT_RX);
- break;
- case DEV_STATE_STARTWAIT_RX:
- if (event == DEV_EVENT_RXUP) {
- fsm_newstate(fi, DEV_STATE_RUNNING);
- dev_info(&dev->dev,
- "Connected with remote side\n");
- ctcm_clear_busy(dev);
- }
- break;
- case DEV_STATE_STARTWAIT_TX:
- if (event == DEV_EVENT_TXUP) {
- fsm_newstate(fi, DEV_STATE_RUNNING);
- dev_info(&dev->dev,
- "Connected with remote side\n");
- ctcm_clear_busy(dev);
- }
- break;
- case DEV_STATE_STOPWAIT_TX:
- if (event == DEV_EVENT_RXUP)
- fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
- break;
- case DEV_STATE_STOPWAIT_RX:
- if (event == DEV_EVENT_TXUP)
- fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
- break;
- }
- if (IS_MPC(priv)) {
- if (event == DEV_EVENT_RXUP)
- mpc_channel_action(priv->channel[CTCM_READ],
- CTCM_READ, MPC_CHANNEL_ADD);
- else
- mpc_channel_action(priv->channel[CTCM_WRITE],
- CTCM_WRITE, MPC_CHANNEL_ADD);
- }
- }
- /**
- * Called from device statemachine
- * when a channel has been shutdown.
- *
- * fi An instance of an interface statemachine.
- * event The event, just happened.
- * arg Generic pointer, casted from struct net_device * upon call.
- */
- static void dev_action_chdown(fsm_instance *fi, int event, void *arg)
- {
- struct net_device *dev = arg;
- struct ctcm_priv *priv = dev->ml_priv;
- CTCMY_DBF_DEV_NAME(SETUP, dev, "");
- switch (fsm_getstate(fi)) {
- case DEV_STATE_RUNNING:
- if (event == DEV_EVENT_TXDOWN)
- fsm_newstate(fi, DEV_STATE_STARTWAIT_TX);
- else
- fsm_newstate(fi, DEV_STATE_STARTWAIT_RX);
- break;
- case DEV_STATE_STARTWAIT_RX:
- if (event == DEV_EVENT_TXDOWN)
- fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
- break;
- case DEV_STATE_STARTWAIT_TX:
- if (event == DEV_EVENT_RXDOWN)
- fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
- break;
- case DEV_STATE_STOPWAIT_RXTX:
- if (event == DEV_EVENT_TXDOWN)
- fsm_newstate(fi, DEV_STATE_STOPWAIT_RX);
- else
- fsm_newstate(fi, DEV_STATE_STOPWAIT_TX);
- break;
- case DEV_STATE_STOPWAIT_RX:
- if (event == DEV_EVENT_RXDOWN)
- fsm_newstate(fi, DEV_STATE_STOPPED);
- break;
- case DEV_STATE_STOPWAIT_TX:
- if (event == DEV_EVENT_TXDOWN)
- fsm_newstate(fi, DEV_STATE_STOPPED);
- break;
- }
- if (IS_MPC(priv)) {
- if (event == DEV_EVENT_RXDOWN)
- mpc_channel_action(priv->channel[CTCM_READ],
- CTCM_READ, MPC_CHANNEL_REMOVE);
- else
- mpc_channel_action(priv->channel[CTCM_WRITE],
- CTCM_WRITE, MPC_CHANNEL_REMOVE);
- }
- }
- const fsm_node dev_fsm[] = {
- { DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start },
- { DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_START, dev_action_start },
- { DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_RXDOWN, dev_action_chdown },
- { DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_TXDOWN, dev_action_chdown },
- { DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_RESTART, dev_action_restart },
- { DEV_STATE_STOPWAIT_RX, DEV_EVENT_START, dev_action_start },
- { DEV_STATE_STOPWAIT_RX, DEV_EVENT_RXUP, dev_action_chup },
- { DEV_STATE_STOPWAIT_RX, DEV_EVENT_TXUP, dev_action_chup },
- { DEV_STATE_STOPWAIT_RX, DEV_EVENT_RXDOWN, dev_action_chdown },
- { DEV_STATE_STOPWAIT_RX, DEV_EVENT_RESTART, dev_action_restart },
- { DEV_STATE_STOPWAIT_TX, DEV_EVENT_START, dev_action_start },
- { DEV_STATE_STOPWAIT_TX, DEV_EVENT_RXUP, dev_action_chup },
- { DEV_STATE_STOPWAIT_TX, DEV_EVENT_TXUP, dev_action_chup },
- { DEV_STATE_STOPWAIT_TX, DEV_EVENT_TXDOWN, dev_action_chdown },
- { DEV_STATE_STOPWAIT_TX, DEV_EVENT_RESTART, dev_action_restart },
- { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_STOP, dev_action_stop },
- { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RXUP, dev_action_chup },
- { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_TXUP, dev_action_chup },
- { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RXDOWN, dev_action_chdown },
- { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_TXDOWN, dev_action_chdown },
- { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RESTART, dev_action_restart },
- { DEV_STATE_STARTWAIT_TX, DEV_EVENT_STOP, dev_action_stop },
- { DEV_STATE_STARTWAIT_TX, DEV_EVENT_RXUP, dev_action_chup },
- { DEV_STATE_STARTWAIT_TX, DEV_EVENT_TXUP, dev_action_chup },
- { DEV_STATE_STARTWAIT_TX, DEV_EVENT_RXDOWN, dev_action_chdown },
- { DEV_STATE_STARTWAIT_TX, DEV_EVENT_RESTART, dev_action_restart },
- { DEV_STATE_STARTWAIT_RX, DEV_EVENT_STOP, dev_action_stop },
- { DEV_STATE_STARTWAIT_RX, DEV_EVENT_RXUP, dev_action_chup },
- { DEV_STATE_STARTWAIT_RX, DEV_EVENT_TXUP, dev_action_chup },
- { DEV_STATE_STARTWAIT_RX, DEV_EVENT_TXDOWN, dev_action_chdown },
- { DEV_STATE_STARTWAIT_RX, DEV_EVENT_RESTART, dev_action_restart },
- { DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop },
- { DEV_STATE_RUNNING, DEV_EVENT_RXDOWN, dev_action_chdown },
- { DEV_STATE_RUNNING, DEV_EVENT_TXDOWN, dev_action_chdown },
- { DEV_STATE_RUNNING, DEV_EVENT_TXUP, ctcm_action_nop },
- { DEV_STATE_RUNNING, DEV_EVENT_RXUP, ctcm_action_nop },
- { DEV_STATE_RUNNING, DEV_EVENT_RESTART, dev_action_restart },
- };
- int dev_fsm_len = ARRAY_SIZE(dev_fsm);
- /* --- This is the END my friend --- */
|