2 * drivers/s390/net/ctcm_fsms.c
4 * Copyright IBM Corp. 2001, 2007
5 * Authors: Fritz Elfert (felfert@millenux.com)
6 * Peter Tiedemann (ptiedem@de.ibm.com)
8 * Belinda Thompson (belindat@us.ibm.com)
9 * Andy Richter (richtera@us.ibm.com)
16 #define KMSG_COMPONENT "ctcm"
17 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/slab.h>
23 #include <linux/errno.h>
24 #include <linux/types.h>
25 #include <linux/interrupt.h>
26 #include <linux/timer.h>
27 #include <linux/bitops.h>
29 #include <linux/signal.h>
30 #include <linux/string.h>
33 #include <linux/if_arp.h>
34 #include <linux/tcp.h>
35 #include <linux/skbuff.h>
36 #include <linux/ctype.h>
40 #include <asm/ccwdev.h>
41 #include <asm/ccwgroup.h>
42 #include <linux/uaccess.h>
44 #include <asm/idals.h>
49 #include "ctcm_dbug.h"
50 #include "ctcm_main.h"
51 #include "ctcm_fsms.h"
53 const char *dev_state_names[] = {
54 [DEV_STATE_STOPPED] = "Stopped",
55 [DEV_STATE_STARTWAIT_RXTX] = "StartWait RXTX",
56 [DEV_STATE_STARTWAIT_RX] = "StartWait RX",
57 [DEV_STATE_STARTWAIT_TX] = "StartWait TX",
58 [DEV_STATE_STOPWAIT_RXTX] = "StopWait RXTX",
59 [DEV_STATE_STOPWAIT_RX] = "StopWait RX",
60 [DEV_STATE_STOPWAIT_TX] = "StopWait TX",
61 [DEV_STATE_RUNNING] = "Running",
64 const char *dev_event_names[] = {
65 [DEV_EVENT_START] = "Start",
66 [DEV_EVENT_STOP] = "Stop",
67 [DEV_EVENT_RXUP] = "RX up",
68 [DEV_EVENT_TXUP] = "TX up",
69 [DEV_EVENT_RXDOWN] = "RX down",
70 [DEV_EVENT_TXDOWN] = "TX down",
71 [DEV_EVENT_RESTART] = "Restart",
74 const char *ctc_ch_event_names[] = {
75 [CTC_EVENT_IO_SUCCESS] = "ccw_device success",
76 [CTC_EVENT_IO_EBUSY] = "ccw_device busy",
77 [CTC_EVENT_IO_ENODEV] = "ccw_device enodev",
78 [CTC_EVENT_IO_UNKNOWN] = "ccw_device unknown",
79 [CTC_EVENT_ATTNBUSY] = "Status ATTN & BUSY",
80 [CTC_EVENT_ATTN] = "Status ATTN",
81 [CTC_EVENT_BUSY] = "Status BUSY",
82 [CTC_EVENT_UC_RCRESET] = "Unit check remote reset",
83 [CTC_EVENT_UC_RSRESET] = "Unit check remote system reset",
84 [CTC_EVENT_UC_TXTIMEOUT] = "Unit check TX timeout",
85 [CTC_EVENT_UC_TXPARITY] = "Unit check TX parity",
86 [CTC_EVENT_UC_HWFAIL] = "Unit check Hardware failure",
87 [CTC_EVENT_UC_RXPARITY] = "Unit check RX parity",
88 [CTC_EVENT_UC_ZERO] = "Unit check ZERO",
89 [CTC_EVENT_UC_UNKNOWN] = "Unit check Unknown",
90 [CTC_EVENT_SC_UNKNOWN] = "SubChannel check Unknown",
91 [CTC_EVENT_MC_FAIL] = "Machine check failure",
92 [CTC_EVENT_MC_GOOD] = "Machine check operational",
93 [CTC_EVENT_IRQ] = "IRQ normal",
94 [CTC_EVENT_FINSTAT] = "IRQ final",
95 [CTC_EVENT_TIMER] = "Timer",
96 [CTC_EVENT_START] = "Start",
97 [CTC_EVENT_STOP] = "Stop",
99 * additional MPC events
101 [CTC_EVENT_SEND_XID] = "XID Exchange",
102 [CTC_EVENT_RSWEEP_TIMER] = "MPC Group Sweep Timer",
105 const char *ctc_ch_state_names[] = {
106 [CTC_STATE_IDLE] = "Idle",
107 [CTC_STATE_STOPPED] = "Stopped",
108 [CTC_STATE_STARTWAIT] = "StartWait",
109 [CTC_STATE_STARTRETRY] = "StartRetry",
110 [CTC_STATE_SETUPWAIT] = "SetupWait",
111 [CTC_STATE_RXINIT] = "RX init",
112 [CTC_STATE_TXINIT] = "TX init",
113 [CTC_STATE_RX] = "RX",
114 [CTC_STATE_TX] = "TX",
115 [CTC_STATE_RXIDLE] = "RX idle",
116 [CTC_STATE_TXIDLE] = "TX idle",
117 [CTC_STATE_RXERR] = "RX error",
118 [CTC_STATE_TXERR] = "TX error",
119 [CTC_STATE_TERM] = "Terminating",
120 [CTC_STATE_DTERM] = "Restarting",
121 [CTC_STATE_NOTOP] = "Not operational",
123 * additional MPC states
125 [CH_XID0_PENDING] = "Pending XID0 Start",
126 [CH_XID0_INPROGRESS] = "In XID0 Negotiations ",
127 [CH_XID7_PENDING] = "Pending XID7 P1 Start",
128 [CH_XID7_PENDING1] = "Active XID7 P1 Exchange ",
129 [CH_XID7_PENDING2] = "Pending XID7 P2 Start ",
130 [CH_XID7_PENDING3] = "Active XID7 P2 Exchange ",
131 [CH_XID7_PENDING4] = "XID7 Complete - Pending READY ",
134 static void ctcm_action_nop(fsm_instance *fi, int event, void *arg);
137 * ----- static ctcm actions for channel statemachine -----
140 static void chx_txdone(fsm_instance *fi, int event, void *arg);
141 static void chx_rx(fsm_instance *fi, int event, void *arg);
142 static void chx_rxidle(fsm_instance *fi, int event, void *arg);
143 static void chx_firstio(fsm_instance *fi, int event, void *arg);
144 static void ctcm_chx_setmode(fsm_instance *fi, int event, void *arg);
145 static void ctcm_chx_start(fsm_instance *fi, int event, void *arg);
146 static void ctcm_chx_haltio(fsm_instance *fi, int event, void *arg);
147 static void ctcm_chx_stopped(fsm_instance *fi, int event, void *arg);
148 static void ctcm_chx_stop(fsm_instance *fi, int event, void *arg);
149 static void ctcm_chx_fail(fsm_instance *fi, int event, void *arg);
150 static void ctcm_chx_setuperr(fsm_instance *fi, int event, void *arg);
151 static void ctcm_chx_restart(fsm_instance *fi, int event, void *arg);
152 static void ctcm_chx_rxiniterr(fsm_instance *fi, int event, void *arg);
153 static void ctcm_chx_rxinitfail(fsm_instance *fi, int event, void *arg);
154 static void ctcm_chx_rxdisc(fsm_instance *fi, int event, void *arg);
155 static void ctcm_chx_txiniterr(fsm_instance *fi, int event, void *arg);
156 static void ctcm_chx_txretry(fsm_instance *fi, int event, void *arg);
157 static void ctcm_chx_iofatal(fsm_instance *fi, int event, void *arg);
160 * ----- static ctcmpc actions for ctcmpc channel statemachine -----
163 static void ctcmpc_chx_txdone(fsm_instance *fi, int event, void *arg);
164 static void ctcmpc_chx_rx(fsm_instance *fi, int event, void *arg);
165 static void ctcmpc_chx_firstio(fsm_instance *fi, int event, void *arg);
167 static void ctcm_chx_setmode(fsm_instance *fi, int event, void *arg);
168 static void ctcm_chx_start(fsm_instance *fi, int event, void *arg);
169 static void ctcm_chx_haltio(fsm_instance *fi, int event, void *arg);
170 static void ctcm_chx_stopped(fsm_instance *fi, int event, void *arg);
171 static void ctcm_chx_stop(fsm_instance *fi, int event, void *arg);
172 static void ctcm_chx_fail(fsm_instance *fi, int event, void *arg);
173 static void ctcm_chx_setuperr(fsm_instance *fi, int event, void *arg);
174 static void ctcm_chx_restart(fsm_instance *fi, int event, void *arg);
175 static void ctcm_chx_rxiniterr(fsm_instance *fi, int event, void *arg);
176 static void ctcm_chx_rxinitfail(fsm_instance *fi, int event, void *arg);
177 static void ctcm_chx_rxdisc(fsm_instance *fi, int event, void *arg);
178 static void ctcm_chx_txiniterr(fsm_instance *fi, int event, void *arg);
179 static void ctcm_chx_txretry(fsm_instance *fi, int event, void *arg);
180 static void ctcm_chx_iofatal(fsm_instance *fi, int event, void *arg);
182 static void ctcmpc_chx_attn(fsm_instance *fsm, int event, void *arg);
183 static void ctcmpc_chx_attnbusy(fsm_instance *, int, void *);
184 static void ctcmpc_chx_resend(fsm_instance *, int, void *);
185 static void ctcmpc_chx_send_sweep(fsm_instance *fsm, int event, void *arg);
188 * Check return code of a preceeding ccw_device call, halt_IO etc...
190 * ch : The channel, the error belongs to.
191 * Returns the error code (!= 0) to inspect.
193 void ctcm_ccw_check_rc(struct channel *ch, int rc, char *msg)
195 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
196 "%s(%s): %s: %04x\n",
197 CTCM_FUNTAIL, ch->id, msg, rc);
200 pr_info("%s: The communication peer is busy\n",
202 fsm_event(ch->fsm, CTC_EVENT_IO_EBUSY, ch);
205 pr_err("%s: The specified target device is not valid\n",
207 fsm_event(ch->fsm, CTC_EVENT_IO_ENODEV, ch);
210 pr_err("An I/O operation resulted in error %04x\n",
212 fsm_event(ch->fsm, CTC_EVENT_IO_UNKNOWN, ch);
216 void ctcm_purge_skb_queue(struct sk_buff_head *q)
220 CTCM_DBF_TEXT(TRACE, CTC_DBF_DEBUG, __func__);
222 while ((skb = skb_dequeue(q))) {
223 atomic_dec(&skb->users);
224 dev_kfree_skb_any(skb);
229 * NOP action for statemachines
231 static void ctcm_action_nop(fsm_instance *fi, int event, void *arg)
236 * Actions for channel - statemachines.
240 * Normal data has been send. Free the corresponding
241 * skb (it's in io_queue), reset dev->tbusy and
242 * revert to idle state.
244 * fi An instance of a channel statemachine.
245 * event The event, just happened.
246 * arg Generic pointer, casted from channel * upon call.
248 static void chx_txdone(fsm_instance *fi, int event, void *arg)
250 struct channel *ch = arg;
251 struct net_device *dev = ch->netdev;
252 struct ctcm_priv *priv = dev->ml_priv;
256 unsigned long duration;
257 struct timespec done_stamp = current_kernel_time(); /* xtime */
259 CTCM_PR_DEBUG("%s(%s): %s\n", __func__, ch->id, dev->name);
262 (done_stamp.tv_sec - ch->prof.send_stamp.tv_sec) * 1000000 +
263 (done_stamp.tv_nsec - ch->prof.send_stamp.tv_nsec) / 1000;
264 if (duration > ch->prof.tx_time)
265 ch->prof.tx_time = duration;
267 if (ch->irb->scsw.cmd.count != 0)
268 CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
269 "%s(%s): TX not complete, remaining %d bytes",
270 CTCM_FUNTAIL, dev->name, ch->irb->scsw.cmd.count);
271 fsm_deltimer(&ch->timer);
272 while ((skb = skb_dequeue(&ch->io_queue))) {
273 priv->stats.tx_packets++;
274 priv->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
276 priv->stats.tx_bytes += 2;
279 atomic_dec(&skb->users);
280 dev_kfree_skb_irq(skb);
282 spin_lock(&ch->collect_lock);
283 clear_normalized_cda(&ch->ccw[4]);
284 if (ch->collect_len > 0) {
287 if (ctcm_checkalloc_buffer(ch)) {
288 spin_unlock(&ch->collect_lock);
291 ch->trans_skb->data = ch->trans_skb_data;
292 skb_reset_tail_pointer(ch->trans_skb);
293 ch->trans_skb->len = 0;
294 if (ch->prof.maxmulti < (ch->collect_len + 2))
295 ch->prof.maxmulti = ch->collect_len + 2;
296 if (ch->prof.maxcqueue < skb_queue_len(&ch->collect_queue))
297 ch->prof.maxcqueue = skb_queue_len(&ch->collect_queue);
298 *((__u16 *)skb_put(ch->trans_skb, 2)) = ch->collect_len + 2;
300 while ((skb = skb_dequeue(&ch->collect_queue))) {
301 skb_copy_from_linear_data(skb,
302 skb_put(ch->trans_skb, skb->len), skb->len);
303 priv->stats.tx_packets++;
304 priv->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
305 atomic_dec(&skb->users);
306 dev_kfree_skb_irq(skb);
310 spin_unlock(&ch->collect_lock);
311 ch->ccw[1].count = ch->trans_skb->len;
312 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
313 ch->prof.send_stamp = current_kernel_time(); /* xtime */
314 rc = ccw_device_start(ch->cdev, &ch->ccw[0],
315 (unsigned long)ch, 0xff, 0);
316 ch->prof.doios_multi++;
318 priv->stats.tx_dropped += i;
319 priv->stats.tx_errors += i;
320 fsm_deltimer(&ch->timer);
321 ctcm_ccw_check_rc(ch, rc, "chained TX");
324 spin_unlock(&ch->collect_lock);
325 fsm_newstate(fi, CTC_STATE_TXIDLE);
327 ctcm_clear_busy_do(dev);
331 * Initial data is sent.
332 * Notify device statemachine that we are up and
335 * fi An instance of a channel statemachine.
336 * event The event, just happened.
337 * arg Generic pointer, casted from channel * upon call.
339 void ctcm_chx_txidle(fsm_instance *fi, int event, void *arg)
341 struct channel *ch = arg;
342 struct net_device *dev = ch->netdev;
343 struct ctcm_priv *priv = dev->ml_priv;
345 CTCM_PR_DEBUG("%s(%s): %s\n", __func__, ch->id, dev->name);
347 fsm_deltimer(&ch->timer);
348 fsm_newstate(fi, CTC_STATE_TXIDLE);
349 fsm_event(priv->fsm, DEV_EVENT_TXUP, ch->netdev);
353 * Got normal data, check for sanity, queue it up, allocate new buffer
354 * trigger bottom half, and initiate next read.
356 * fi An instance of a channel statemachine.
357 * event The event, just happened.
358 * arg Generic pointer, casted from channel * upon call.
360 static void chx_rx(fsm_instance *fi, int event, void *arg)
362 struct channel *ch = arg;
363 struct net_device *dev = ch->netdev;
364 struct ctcm_priv *priv = dev->ml_priv;
365 int len = ch->max_bufsize - ch->irb->scsw.cmd.count;
366 struct sk_buff *skb = ch->trans_skb;
367 __u16 block_len = *((__u16 *)skb->data);
371 fsm_deltimer(&ch->timer);
373 CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
374 "%s(%s): got packet with length %d < 8\n",
375 CTCM_FUNTAIL, dev->name, len);
376 priv->stats.rx_dropped++;
377 priv->stats.rx_length_errors++;
380 if (len > ch->max_bufsize) {
381 CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
382 "%s(%s): got packet with length %d > %d\n",
383 CTCM_FUNTAIL, dev->name, len, ch->max_bufsize);
384 priv->stats.rx_dropped++;
385 priv->stats.rx_length_errors++;
390 * VM TCP seems to have a bug sending 2 trailing bytes of garbage.
392 switch (ch->protocol) {
393 case CTCM_PROTO_S390:
394 case CTCM_PROTO_OS390:
395 check_len = block_len + 2;
398 check_len = block_len;
401 if ((len < block_len) || (len > check_len)) {
402 CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
403 "%s(%s): got block length %d != rx length %d\n",
404 CTCM_FUNTAIL, dev->name, block_len, len);
406 ctcmpc_dump_skb(skb, 0);
408 *((__u16 *)skb->data) = len;
409 priv->stats.rx_dropped++;
410 priv->stats.rx_length_errors++;
415 *((__u16 *)skb->data) = block_len;
416 ctcm_unpack_skb(ch, skb);
419 skb->data = ch->trans_skb_data;
420 skb_reset_tail_pointer(skb);
422 if (ctcm_checkalloc_buffer(ch))
424 ch->ccw[1].count = ch->max_bufsize;
425 rc = ccw_device_start(ch->cdev, &ch->ccw[0],
426 (unsigned long)ch, 0xff, 0);
428 ctcm_ccw_check_rc(ch, rc, "normal RX");
432 * Initialize connection by sending a __u16 of value 0.
434 * fi An instance of a channel statemachine.
435 * event The event, just happened.
436 * arg Generic pointer, casted from channel * upon call.
438 static void chx_firstio(fsm_instance *fi, int event, void *arg)
441 struct channel *ch = arg;
442 int fsmstate = fsm_getstate(fi);
444 CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
446 CTCM_FUNTAIL, ch->id, fsmstate);
448 ch->sense_rc = 0; /* reset unit check report control */
449 if (fsmstate == CTC_STATE_TXIDLE)
450 CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
451 "%s(%s): remote side issued READ?, init.\n",
452 CTCM_FUNTAIL, ch->id);
453 fsm_deltimer(&ch->timer);
454 if (ctcm_checkalloc_buffer(ch))
456 if ((fsmstate == CTC_STATE_SETUPWAIT) &&
457 (ch->protocol == CTCM_PROTO_OS390)) {
458 /* OS/390 resp. z/OS */
459 if (CHANNEL_DIRECTION(ch->flags) == READ) {
460 *((__u16 *)ch->trans_skb->data) = CTCM_INITIAL_BLOCKLEN;
461 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC,
462 CTC_EVENT_TIMER, ch);
463 chx_rxidle(fi, event, arg);
465 struct net_device *dev = ch->netdev;
466 struct ctcm_priv *priv = dev->ml_priv;
467 fsm_newstate(fi, CTC_STATE_TXIDLE);
468 fsm_event(priv->fsm, DEV_EVENT_TXUP, dev);
473 * Don't setup a timer for receiving the initial RX frame
474 * if in compatibility mode, since VM TCP delays the initial
475 * frame until it has some data to send.
477 if ((CHANNEL_DIRECTION(ch->flags) == WRITE) ||
478 (ch->protocol != CTCM_PROTO_S390))
479 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
481 *((__u16 *)ch->trans_skb->data) = CTCM_INITIAL_BLOCKLEN;
482 ch->ccw[1].count = 2; /* Transfer only length */
484 fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == READ)
485 ? CTC_STATE_RXINIT : CTC_STATE_TXINIT);
486 rc = ccw_device_start(ch->cdev, &ch->ccw[0],
487 (unsigned long)ch, 0xff, 0);
489 fsm_deltimer(&ch->timer);
490 fsm_newstate(fi, CTC_STATE_SETUPWAIT);
491 ctcm_ccw_check_rc(ch, rc, "init IO");
494 * If in compatibility mode since we don't setup a timer, we
495 * also signal RX channel up immediately. This enables us
496 * to send packets early which in turn usually triggers some
497 * reply from VM TCP which brings up the RX channel to it's
500 if ((CHANNEL_DIRECTION(ch->flags) == READ) &&
501 (ch->protocol == CTCM_PROTO_S390)) {
502 struct net_device *dev = ch->netdev;
503 struct ctcm_priv *priv = dev->ml_priv;
504 fsm_event(priv->fsm, DEV_EVENT_RXUP, dev);
509 * Got initial data, check it. If OK,
510 * notify device statemachine that we are up and
513 * fi An instance of a channel statemachine.
514 * event The event, just happened.
515 * arg Generic pointer, casted from channel * upon call.
517 static void chx_rxidle(fsm_instance *fi, int event, void *arg)
519 struct channel *ch = arg;
520 struct net_device *dev = ch->netdev;
521 struct ctcm_priv *priv = dev->ml_priv;
525 fsm_deltimer(&ch->timer);
526 buflen = *((__u16 *)ch->trans_skb->data);
527 CTCM_PR_DEBUG("%s: %s: Initial RX count = %d\n",
528 __func__, dev->name, buflen);
530 if (buflen >= CTCM_INITIAL_BLOCKLEN) {
531 if (ctcm_checkalloc_buffer(ch))
533 ch->ccw[1].count = ch->max_bufsize;
534 fsm_newstate(fi, CTC_STATE_RXIDLE);
535 rc = ccw_device_start(ch->cdev, &ch->ccw[0],
536 (unsigned long)ch, 0xff, 0);
538 fsm_newstate(fi, CTC_STATE_RXINIT);
539 ctcm_ccw_check_rc(ch, rc, "initial RX");
541 fsm_event(priv->fsm, DEV_EVENT_RXUP, dev);
543 CTCM_PR_DEBUG("%s: %s: Initial RX count %d not %d\n",
545 buflen, CTCM_INITIAL_BLOCKLEN);
546 chx_firstio(fi, event, arg);
551 * Set channel into extended mode.
553 * fi An instance of a channel statemachine.
554 * event The event, just happened.
555 * arg Generic pointer, casted from channel * upon call.
557 static void ctcm_chx_setmode(fsm_instance *fi, int event, void *arg)
559 struct channel *ch = arg;
561 unsigned long saveflags = 0;
562 int timeout = CTCM_TIME_5_SEC;
564 fsm_deltimer(&ch->timer);
567 CTCM_PR_DEBUG("enter %s: cp=%i ch=0x%p id=%s\n",
568 __func__, smp_processor_id(), ch, ch->id);
570 fsm_addtimer(&ch->timer, timeout, CTC_EVENT_TIMER, ch);
571 fsm_newstate(fi, CTC_STATE_SETUPWAIT);
572 CTCM_CCW_DUMP((char *)&ch->ccw[6], sizeof(struct ccw1) * 2);
574 if (event == CTC_EVENT_TIMER) /* only for timer not yet locked */
575 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
576 /* Such conditional locking is undeterministic in
577 * static view. => ignore sparse warnings here. */
579 rc = ccw_device_start(ch->cdev, &ch->ccw[6],
580 (unsigned long)ch, 0xff, 0);
581 if (event == CTC_EVENT_TIMER) /* see above comments */
582 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
584 fsm_deltimer(&ch->timer);
585 fsm_newstate(fi, CTC_STATE_STARTWAIT);
586 ctcm_ccw_check_rc(ch, rc, "set Mode");
594 * fi An instance of a channel statemachine.
595 * event The event, just happened.
596 * arg Generic pointer, casted from channel * upon call.
598 static void ctcm_chx_start(fsm_instance *fi, int event, void *arg)
600 struct channel *ch = arg;
601 unsigned long saveflags;
604 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s): %s",
605 CTCM_FUNTAIL, ch->id,
606 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
608 if (ch->trans_skb != NULL) {
609 clear_normalized_cda(&ch->ccw[1]);
610 dev_kfree_skb(ch->trans_skb);
611 ch->trans_skb = NULL;
613 if (CHANNEL_DIRECTION(ch->flags) == READ) {
614 ch->ccw[1].cmd_code = CCW_CMD_READ;
615 ch->ccw[1].flags = CCW_FLAG_SLI;
616 ch->ccw[1].count = 0;
618 ch->ccw[1].cmd_code = CCW_CMD_WRITE;
619 ch->ccw[1].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
620 ch->ccw[1].count = 0;
622 if (ctcm_checkalloc_buffer(ch)) {
623 CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
624 "%s(%s): %s trans_skb alloc delayed "
625 "until first transfer",
626 CTCM_FUNTAIL, ch->id,
627 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
629 ch->ccw[0].cmd_code = CCW_CMD_PREPARE;
630 ch->ccw[0].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
631 ch->ccw[0].count = 0;
633 ch->ccw[2].cmd_code = CCW_CMD_NOOP; /* jointed CE + DE */
634 ch->ccw[2].flags = CCW_FLAG_SLI;
635 ch->ccw[2].count = 0;
637 memcpy(&ch->ccw[3], &ch->ccw[0], sizeof(struct ccw1) * 3);
639 ch->ccw[4].flags &= ~CCW_FLAG_IDA;
641 fsm_newstate(fi, CTC_STATE_STARTWAIT);
642 fsm_addtimer(&ch->timer, 1000, CTC_EVENT_TIMER, ch);
643 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
644 rc = ccw_device_halt(ch->cdev, (unsigned long)ch);
645 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
648 fsm_deltimer(&ch->timer);
649 ctcm_ccw_check_rc(ch, rc, "initial HaltIO");
654 * Shutdown a channel.
656 * fi An instance of a channel statemachine.
657 * event The event, just happened.
658 * arg Generic pointer, casted from channel * upon call.
660 static void ctcm_chx_haltio(fsm_instance *fi, int event, void *arg)
662 struct channel *ch = arg;
663 unsigned long saveflags = 0;
667 fsm_deltimer(&ch->timer);
669 fsm_deltimer(&ch->sweep_timer);
671 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
673 if (event == CTC_EVENT_STOP) /* only for STOP not yet locked */
674 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
675 /* Such conditional locking is undeterministic in
676 * static view. => ignore sparse warnings here. */
677 oldstate = fsm_getstate(fi);
678 fsm_newstate(fi, CTC_STATE_TERM);
679 rc = ccw_device_halt(ch->cdev, (unsigned long)ch);
681 if (event == CTC_EVENT_STOP)
682 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
683 /* see remark above about conditional locking */
685 if (rc != 0 && rc != -EBUSY) {
686 fsm_deltimer(&ch->timer);
687 if (event != CTC_EVENT_STOP) {
688 fsm_newstate(fi, oldstate);
689 ctcm_ccw_check_rc(ch, rc, (char *)__func__);
695 * Cleanup helper for chx_fail and chx_stopped
696 * cleanup channels queue and notify interface statemachine.
698 * fi An instance of a channel statemachine.
699 * state The next state (depending on caller).
700 * ch The channel to operate on.
702 static void ctcm_chx_cleanup(fsm_instance *fi, int state,
705 struct net_device *dev = ch->netdev;
706 struct ctcm_priv *priv = dev->ml_priv;
708 CTCM_DBF_TEXT_(SETUP, CTC_DBF_NOTICE,
710 CTCM_FUNTAIL, dev->name, ch->id, state);
712 fsm_deltimer(&ch->timer);
714 fsm_deltimer(&ch->sweep_timer);
716 fsm_newstate(fi, state);
717 if (state == CTC_STATE_STOPPED && ch->trans_skb != NULL) {
718 clear_normalized_cda(&ch->ccw[1]);
719 dev_kfree_skb_any(ch->trans_skb);
720 ch->trans_skb = NULL;
724 ch->th_seq_num = 0x00;
725 if (CHANNEL_DIRECTION(ch->flags) == READ) {
726 skb_queue_purge(&ch->io_queue);
727 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
729 ctcm_purge_skb_queue(&ch->io_queue);
731 ctcm_purge_skb_queue(&ch->sweep_queue);
732 spin_lock(&ch->collect_lock);
733 ctcm_purge_skb_queue(&ch->collect_queue);
735 spin_unlock(&ch->collect_lock);
736 fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
741 * A channel has successfully been halted.
742 * Cleanup it's queue and notify interface statemachine.
744 * fi An instance of a channel statemachine.
745 * event The event, just happened.
746 * arg Generic pointer, casted from channel * upon call.
748 static void ctcm_chx_stopped(fsm_instance *fi, int event, void *arg)
750 ctcm_chx_cleanup(fi, CTC_STATE_STOPPED, arg);
754 * A stop command from device statemachine arrived and we are in
755 * not operational mode. Set state to stopped.
757 * fi An instance of a channel statemachine.
758 * event The event, just happened.
759 * arg Generic pointer, casted from channel * upon call.
761 static void ctcm_chx_stop(fsm_instance *fi, int event, void *arg)
763 fsm_newstate(fi, CTC_STATE_STOPPED);
767 * A machine check for no path, not operational status or gone device has
769 * Cleanup queue and notify interface statemachine.
771 * fi An instance of a channel statemachine.
772 * event The event, just happened.
773 * arg Generic pointer, casted from channel * upon call.
775 static void ctcm_chx_fail(fsm_instance *fi, int event, void *arg)
777 ctcm_chx_cleanup(fi, CTC_STATE_NOTOP, arg);
781 * Handle error during setup of channel.
783 * fi An instance of a channel statemachine.
784 * event The event, just happened.
785 * arg Generic pointer, casted from channel * upon call.
787 static void ctcm_chx_setuperr(fsm_instance *fi, int event, void *arg)
789 struct channel *ch = arg;
790 struct net_device *dev = ch->netdev;
791 struct ctcm_priv *priv = dev->ml_priv;
794 * Special case: Got UC_RCRESET on setmode.
795 * This means that remote side isn't setup. In this case
796 * simply retry after some 10 secs...
798 if ((fsm_getstate(fi) == CTC_STATE_SETUPWAIT) &&
799 ((event == CTC_EVENT_UC_RCRESET) ||
800 (event == CTC_EVENT_UC_RSRESET))) {
801 fsm_newstate(fi, CTC_STATE_STARTRETRY);
802 fsm_deltimer(&ch->timer);
803 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
804 if (!IS_MPC(ch) && (CHANNEL_DIRECTION(ch->flags) == READ)) {
805 int rc = ccw_device_halt(ch->cdev, (unsigned long)ch);
807 ctcm_ccw_check_rc(ch, rc,
808 "HaltIO in chx_setuperr");
813 CTCM_DBF_TEXT_(ERROR, CTC_DBF_CRIT,
814 "%s(%s) : %s error during %s channel setup state=%s\n",
815 CTCM_FUNTAIL, dev->name, ctc_ch_event_names[event],
816 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX",
817 fsm_getstate_str(fi));
819 if (CHANNEL_DIRECTION(ch->flags) == READ) {
820 fsm_newstate(fi, CTC_STATE_RXERR);
821 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
823 fsm_newstate(fi, CTC_STATE_TXERR);
824 fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
829 * Restart a channel after an error.
831 * fi An instance of a channel statemachine.
832 * event The event, just happened.
833 * arg Generic pointer, casted from channel * upon call.
835 static void ctcm_chx_restart(fsm_instance *fi, int event, void *arg)
837 struct channel *ch = arg;
838 struct net_device *dev = ch->netdev;
839 unsigned long saveflags = 0;
843 CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
844 "%s: %s[%d] of %s\n",
845 CTCM_FUNTAIL, ch->id, event, dev->name);
847 fsm_deltimer(&ch->timer);
849 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
850 oldstate = fsm_getstate(fi);
851 fsm_newstate(fi, CTC_STATE_STARTWAIT);
852 if (event == CTC_EVENT_TIMER) /* only for timer not yet locked */
853 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
854 /* Such conditional locking is a known problem for
855 * sparse because its undeterministic in static view.
856 * Warnings should be ignored here. */
857 rc = ccw_device_halt(ch->cdev, (unsigned long)ch);
858 if (event == CTC_EVENT_TIMER)
859 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
862 fsm_deltimer(&ch->timer);
863 fsm_newstate(fi, oldstate);
865 ctcm_ccw_check_rc(ch, rc, "HaltIO in ctcm_chx_restart");
870 * Handle error during RX initial handshake (exchange of
871 * 0-length block header)
873 * fi An instance of a channel statemachine.
874 * event The event, just happened.
875 * arg Generic pointer, casted from channel * upon call.
877 static void ctcm_chx_rxiniterr(fsm_instance *fi, int event, void *arg)
879 struct channel *ch = arg;
880 struct net_device *dev = ch->netdev;
881 struct ctcm_priv *priv = dev->ml_priv;
883 if (event == CTC_EVENT_TIMER) {
885 /* TODO : check if MPC deletes timer somewhere */
886 fsm_deltimer(&ch->timer);
888 ctcm_chx_restart(fi, event, arg);
890 fsm_newstate(fi, CTC_STATE_RXERR);
891 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
894 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
895 "%s(%s): %s in %s", CTCM_FUNTAIL, ch->id,
896 ctc_ch_event_names[event], fsm_getstate_str(fi));
899 "Initialization failed with RX/TX init handshake "
900 "error %s\n", ctc_ch_event_names[event]);
905 * Notify device statemachine if we gave up initialization
908 * fi An instance of a channel statemachine.
909 * event The event, just happened.
910 * arg Generic pointer, casted from channel * upon call.
912 static void ctcm_chx_rxinitfail(fsm_instance *fi, int event, void *arg)
914 struct channel *ch = arg;
915 struct net_device *dev = ch->netdev;
916 struct ctcm_priv *priv = dev->ml_priv;
918 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
919 "%s(%s): RX %s busy, init. fail",
920 CTCM_FUNTAIL, dev->name, ch->id);
921 fsm_newstate(fi, CTC_STATE_RXERR);
922 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
926 * Handle RX Unit check remote reset (remote disconnected)
928 * fi An instance of a channel statemachine.
929 * event The event, just happened.
930 * arg Generic pointer, casted from channel * upon call.
932 static void ctcm_chx_rxdisc(fsm_instance *fi, int event, void *arg)
934 struct channel *ch = arg;
936 struct net_device *dev = ch->netdev;
937 struct ctcm_priv *priv = dev->ml_priv;
939 CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
940 "%s: %s: remote disconnect - re-init ...",
941 CTCM_FUNTAIL, dev->name);
942 fsm_deltimer(&ch->timer);
944 * Notify device statemachine
946 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
947 fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
949 fsm_newstate(fi, CTC_STATE_DTERM);
950 ch2 = priv->channel[WRITE];
951 fsm_newstate(ch2->fsm, CTC_STATE_DTERM);
953 ccw_device_halt(ch->cdev, (unsigned long)ch);
954 ccw_device_halt(ch2->cdev, (unsigned long)ch2);
958 * Handle error during TX channel initialization.
960 * fi An instance of a channel statemachine.
961 * event The event, just happened.
962 * arg Generic pointer, casted from channel * upon call.
964 static void ctcm_chx_txiniterr(fsm_instance *fi, int event, void *arg)
966 struct channel *ch = arg;
967 struct net_device *dev = ch->netdev;
968 struct ctcm_priv *priv = dev->ml_priv;
970 if (event == CTC_EVENT_TIMER) {
971 fsm_deltimer(&ch->timer);
973 ctcm_chx_restart(fi, event, arg);
975 fsm_newstate(fi, CTC_STATE_TXERR);
976 fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
979 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
980 "%s(%s): %s in %s", CTCM_FUNTAIL, ch->id,
981 ctc_ch_event_names[event], fsm_getstate_str(fi));
984 "Initialization failed with RX/TX init handshake "
985 "error %s\n", ctc_ch_event_names[event]);
990 * Handle TX timeout by retrying operation.
992 * fi An instance of a channel statemachine.
993 * event The event, just happened.
994 * arg Generic pointer, casted from channel * upon call.
996 static void ctcm_chx_txretry(fsm_instance *fi, int event, void *arg)
998 struct channel *ch = arg;
999 struct net_device *dev = ch->netdev;
1000 struct ctcm_priv *priv = dev->ml_priv;
1001 struct sk_buff *skb;
1003 CTCM_PR_DEBUG("Enter: %s: cp=%i ch=0x%p id=%s\n",
1004 __func__, smp_processor_id(), ch, ch->id);
1006 fsm_deltimer(&ch->timer);
1007 if (ch->retry++ > 3) {
1008 struct mpc_group *gptr = priv->mpcg;
1009 CTCM_DBF_TEXT_(TRACE, CTC_DBF_INFO,
1010 "%s: %s: retries exceeded",
1011 CTCM_FUNTAIL, ch->id);
1012 fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
1013 /* call restart if not MPC or if MPC and mpcg fsm is ready.
1014 use gptr as mpc indicator */
1015 if (!(gptr && (fsm_getstate(gptr->fsm) != MPCG_STATE_READY)))
1016 ctcm_chx_restart(fi, event, arg);
1020 CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
1021 "%s : %s: retry %d",
1022 CTCM_FUNTAIL, ch->id, ch->retry);
1023 skb = skb_peek(&ch->io_queue);
1026 unsigned long saveflags = 0;
1027 clear_normalized_cda(&ch->ccw[4]);
1028 ch->ccw[4].count = skb->len;
1029 if (set_normalized_cda(&ch->ccw[4], skb->data)) {
1030 CTCM_DBF_TEXT_(TRACE, CTC_DBF_INFO,
1031 "%s: %s: IDAL alloc failed",
1032 CTCM_FUNTAIL, ch->id);
1033 fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
1034 ctcm_chx_restart(fi, event, arg);
1037 fsm_addtimer(&ch->timer, 1000, CTC_EVENT_TIMER, ch);
1038 if (event == CTC_EVENT_TIMER) /* for TIMER not yet locked */
1039 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1040 /* Such conditional locking is a known problem for
1041 * sparse because its undeterministic in static view.
1042 * Warnings should be ignored here. */
1044 ctcmpc_dumpit((char *)&ch->ccw[3],
1045 sizeof(struct ccw1) * 3);
1047 rc = ccw_device_start(ch->cdev, &ch->ccw[3],
1048 (unsigned long)ch, 0xff, 0);
1049 if (event == CTC_EVENT_TIMER)
1050 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev),
1053 fsm_deltimer(&ch->timer);
1054 ctcm_ccw_check_rc(ch, rc, "TX in chx_txretry");
1055 ctcm_purge_skb_queue(&ch->io_queue);
1063 * Handle fatal errors during an I/O command.
1065 * fi An instance of a channel statemachine.
1066 * event The event, just happened.
1067 * arg Generic pointer, casted from channel * upon call.
1069 static void ctcm_chx_iofatal(fsm_instance *fi, int event, void *arg)
1071 struct channel *ch = arg;
1072 struct net_device *dev = ch->netdev;
1073 struct ctcm_priv *priv = dev->ml_priv;
1074 int rd = CHANNEL_DIRECTION(ch->flags);
1076 fsm_deltimer(&ch->timer);
1077 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
1078 "%s: %s: %s unrecoverable channel error",
1079 CTCM_FUNTAIL, ch->id, rd == READ ? "RX" : "TX");
1082 priv->stats.tx_dropped++;
1083 priv->stats.tx_errors++;
1086 fsm_newstate(fi, CTC_STATE_RXERR);
1087 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
1089 fsm_newstate(fi, CTC_STATE_TXERR);
1090 fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
1095 * The ctcm statemachine for a channel.
1097 const fsm_node ch_fsm[] = {
1098 { CTC_STATE_STOPPED, CTC_EVENT_STOP, ctcm_action_nop },
1099 { CTC_STATE_STOPPED, CTC_EVENT_START, ctcm_chx_start },
1100 { CTC_STATE_STOPPED, CTC_EVENT_FINSTAT, ctcm_action_nop },
1101 { CTC_STATE_STOPPED, CTC_EVENT_MC_FAIL, ctcm_action_nop },
1103 { CTC_STATE_NOTOP, CTC_EVENT_STOP, ctcm_chx_stop },
1104 { CTC_STATE_NOTOP, CTC_EVENT_START, ctcm_action_nop },
1105 { CTC_STATE_NOTOP, CTC_EVENT_FINSTAT, ctcm_action_nop },
1106 { CTC_STATE_NOTOP, CTC_EVENT_MC_FAIL, ctcm_action_nop },
1107 { CTC_STATE_NOTOP, CTC_EVENT_MC_GOOD, ctcm_chx_start },
1109 { CTC_STATE_STARTWAIT, CTC_EVENT_STOP, ctcm_chx_haltio },
1110 { CTC_STATE_STARTWAIT, CTC_EVENT_START, ctcm_action_nop },
1111 { CTC_STATE_STARTWAIT, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
1112 { CTC_STATE_STARTWAIT, CTC_EVENT_TIMER, ctcm_chx_setuperr },
1113 { CTC_STATE_STARTWAIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1114 { CTC_STATE_STARTWAIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1116 { CTC_STATE_STARTRETRY, CTC_EVENT_STOP, ctcm_chx_haltio },
1117 { CTC_STATE_STARTRETRY, CTC_EVENT_TIMER, ctcm_chx_setmode },
1118 { CTC_STATE_STARTRETRY, CTC_EVENT_FINSTAT, ctcm_action_nop },
1119 { CTC_STATE_STARTRETRY, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1121 { CTC_STATE_SETUPWAIT, CTC_EVENT_STOP, ctcm_chx_haltio },
1122 { CTC_STATE_SETUPWAIT, CTC_EVENT_START, ctcm_action_nop },
1123 { CTC_STATE_SETUPWAIT, CTC_EVENT_FINSTAT, chx_firstio },
1124 { CTC_STATE_SETUPWAIT, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
1125 { CTC_STATE_SETUPWAIT, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
1126 { CTC_STATE_SETUPWAIT, CTC_EVENT_TIMER, ctcm_chx_setmode },
1127 { CTC_STATE_SETUPWAIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1128 { CTC_STATE_SETUPWAIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1130 { CTC_STATE_RXINIT, CTC_EVENT_STOP, ctcm_chx_haltio },
1131 { CTC_STATE_RXINIT, CTC_EVENT_START, ctcm_action_nop },
1132 { CTC_STATE_RXINIT, CTC_EVENT_FINSTAT, chx_rxidle },
1133 { CTC_STATE_RXINIT, CTC_EVENT_UC_RCRESET, ctcm_chx_rxiniterr },
1134 { CTC_STATE_RXINIT, CTC_EVENT_UC_RSRESET, ctcm_chx_rxiniterr },
1135 { CTC_STATE_RXINIT, CTC_EVENT_TIMER, ctcm_chx_rxiniterr },
1136 { CTC_STATE_RXINIT, CTC_EVENT_ATTNBUSY, ctcm_chx_rxinitfail },
1137 { CTC_STATE_RXINIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1138 { CTC_STATE_RXINIT, CTC_EVENT_UC_ZERO, chx_firstio },
1139 { CTC_STATE_RXINIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1141 { CTC_STATE_RXIDLE, CTC_EVENT_STOP, ctcm_chx_haltio },
1142 { CTC_STATE_RXIDLE, CTC_EVENT_START, ctcm_action_nop },
1143 { CTC_STATE_RXIDLE, CTC_EVENT_FINSTAT, chx_rx },
1144 { CTC_STATE_RXIDLE, CTC_EVENT_UC_RCRESET, ctcm_chx_rxdisc },
1145 { CTC_STATE_RXIDLE, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1146 { CTC_STATE_RXIDLE, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1147 { CTC_STATE_RXIDLE, CTC_EVENT_UC_ZERO, chx_rx },
1149 { CTC_STATE_TXINIT, CTC_EVENT_STOP, ctcm_chx_haltio },
1150 { CTC_STATE_TXINIT, CTC_EVENT_START, ctcm_action_nop },
1151 { CTC_STATE_TXINIT, CTC_EVENT_FINSTAT, ctcm_chx_txidle },
1152 { CTC_STATE_TXINIT, CTC_EVENT_UC_RCRESET, ctcm_chx_txiniterr },
1153 { CTC_STATE_TXINIT, CTC_EVENT_UC_RSRESET, ctcm_chx_txiniterr },
1154 { CTC_STATE_TXINIT, CTC_EVENT_TIMER, ctcm_chx_txiniterr },
1155 { CTC_STATE_TXINIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1156 { CTC_STATE_TXINIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1158 { CTC_STATE_TXIDLE, CTC_EVENT_STOP, ctcm_chx_haltio },
1159 { CTC_STATE_TXIDLE, CTC_EVENT_START, ctcm_action_nop },
1160 { CTC_STATE_TXIDLE, CTC_EVENT_FINSTAT, chx_firstio },
1161 { CTC_STATE_TXIDLE, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
1162 { CTC_STATE_TXIDLE, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
1163 { CTC_STATE_TXIDLE, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1164 { CTC_STATE_TXIDLE, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1166 { CTC_STATE_TERM, CTC_EVENT_STOP, ctcm_action_nop },
1167 { CTC_STATE_TERM, CTC_EVENT_START, ctcm_chx_restart },
1168 { CTC_STATE_TERM, CTC_EVENT_FINSTAT, ctcm_chx_stopped },
1169 { CTC_STATE_TERM, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
1170 { CTC_STATE_TERM, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
1171 { CTC_STATE_TERM, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1173 { CTC_STATE_DTERM, CTC_EVENT_STOP, ctcm_chx_haltio },
1174 { CTC_STATE_DTERM, CTC_EVENT_START, ctcm_chx_restart },
1175 { CTC_STATE_DTERM, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
1176 { CTC_STATE_DTERM, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
1177 { CTC_STATE_DTERM, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
1178 { CTC_STATE_DTERM, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1180 { CTC_STATE_TX, CTC_EVENT_STOP, ctcm_chx_haltio },
1181 { CTC_STATE_TX, CTC_EVENT_START, ctcm_action_nop },
1182 { CTC_STATE_TX, CTC_EVENT_FINSTAT, chx_txdone },
1183 { CTC_STATE_TX, CTC_EVENT_UC_RCRESET, ctcm_chx_txretry },
1184 { CTC_STATE_TX, CTC_EVENT_UC_RSRESET, ctcm_chx_txretry },
1185 { CTC_STATE_TX, CTC_EVENT_TIMER, ctcm_chx_txretry },
1186 { CTC_STATE_TX, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1187 { CTC_STATE_TX, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1189 { CTC_STATE_RXERR, CTC_EVENT_STOP, ctcm_chx_haltio },
1190 { CTC_STATE_TXERR, CTC_EVENT_STOP, ctcm_chx_haltio },
1191 { CTC_STATE_TXERR, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1192 { CTC_STATE_RXERR, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1195 int ch_fsm_len = ARRAY_SIZE(ch_fsm);
1198 * MPC actions for mpc channel statemachine
1199 * handling of MPC protocol requires extra
1200 * statemachine and actions which are prefixed ctcmpc_ .
1201 * The ctc_ch_states and ctc_ch_state_names,
1202 * ctc_ch_events and ctc_ch_event_names share the ctcm definitions
1203 * which are expanded by some elements.
1207 * Actions for mpc channel statemachine.
1211 * Normal data has been send. Free the corresponding
1212 * skb (it's in io_queue), reset dev->tbusy and
1213 * revert to idle state.
1215 * fi An instance of a channel statemachine.
1216 * event The event, just happened.
1217 * arg Generic pointer, casted from channel * upon call.
1219 static void ctcmpc_chx_txdone(fsm_instance *fi, int event, void *arg)
1221 struct channel *ch = arg;
1222 struct net_device *dev = ch->netdev;
1223 struct ctcm_priv *priv = dev->ml_priv;
1224 struct mpc_group *grp = priv->mpcg;
1225 struct sk_buff *skb;
1229 unsigned long duration;
1230 struct sk_buff *peekskb;
1232 struct th_header *header;
1233 struct pdu *p_header;
1234 struct timespec done_stamp = current_kernel_time(); /* xtime */
1236 CTCM_PR_DEBUG("Enter %s: %s cp:%i\n",
1237 __func__, dev->name, smp_processor_id());
1240 (done_stamp.tv_sec - ch->prof.send_stamp.tv_sec) * 1000000 +
1241 (done_stamp.tv_nsec - ch->prof.send_stamp.tv_nsec) / 1000;
1242 if (duration > ch->prof.tx_time)
1243 ch->prof.tx_time = duration;
1245 if (ch->irb->scsw.cmd.count != 0)
1246 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1247 "%s(%s): TX not complete, remaining %d bytes",
1248 CTCM_FUNTAIL, dev->name, ch->irb->scsw.cmd.count);
1249 fsm_deltimer(&ch->timer);
1250 while ((skb = skb_dequeue(&ch->io_queue))) {
1251 priv->stats.tx_packets++;
1252 priv->stats.tx_bytes += skb->len - TH_HEADER_LENGTH;
1254 priv->stats.tx_bytes += 2;
1257 atomic_dec(&skb->users);
1258 dev_kfree_skb_irq(skb);
1260 spin_lock(&ch->collect_lock);
1261 clear_normalized_cda(&ch->ccw[4]);
1262 if ((ch->collect_len <= 0) || (grp->in_sweep != 0)) {
1263 spin_unlock(&ch->collect_lock);
1264 fsm_newstate(fi, CTC_STATE_TXIDLE);
1268 if (ctcm_checkalloc_buffer(ch)) {
1269 spin_unlock(&ch->collect_lock);
1272 ch->trans_skb->data = ch->trans_skb_data;
1273 skb_reset_tail_pointer(ch->trans_skb);
1274 ch->trans_skb->len = 0;
1275 if (ch->prof.maxmulti < (ch->collect_len + TH_HEADER_LENGTH))
1276 ch->prof.maxmulti = ch->collect_len + TH_HEADER_LENGTH;
1277 if (ch->prof.maxcqueue < skb_queue_len(&ch->collect_queue))
1278 ch->prof.maxcqueue = skb_queue_len(&ch->collect_queue);
1281 data_space = grp->group_max_buflen - TH_HEADER_LENGTH;
1283 CTCM_PR_DBGDATA("%s: building trans_skb from collect_q"
1284 " data_space:%04x\n",
1285 __func__, data_space);
1287 while ((skb = skb_dequeue(&ch->collect_queue))) {
1288 memcpy(skb_put(ch->trans_skb, skb->len), skb->data, skb->len);
1289 p_header = (struct pdu *)
1290 (skb_tail_pointer(ch->trans_skb) - skb->len);
1291 p_header->pdu_flag = 0x00;
1292 if (skb->protocol == ntohs(ETH_P_SNAP))
1293 p_header->pdu_flag |= 0x60;
1295 p_header->pdu_flag |= 0x20;
1297 CTCM_PR_DBGDATA("%s: trans_skb len:%04x \n",
1298 __func__, ch->trans_skb->len);
1299 CTCM_PR_DBGDATA("%s: pdu header and data for up"
1300 " to 32 bytes sent to vtam\n", __func__);
1301 CTCM_D3_DUMP((char *)p_header, min_t(int, skb->len, 32));
1303 ch->collect_len -= skb->len;
1304 data_space -= skb->len;
1305 priv->stats.tx_packets++;
1306 priv->stats.tx_bytes += skb->len;
1307 atomic_dec(&skb->users);
1308 dev_kfree_skb_any(skb);
1309 peekskb = skb_peek(&ch->collect_queue);
1310 if (peekskb->len > data_space)
1314 /* p_header points to the last one we handled */
1316 p_header->pdu_flag |= PDU_LAST; /*Say it's the last one*/
1317 header = kzalloc(TH_HEADER_LENGTH, gfp_type());
1319 spin_unlock(&ch->collect_lock);
1320 fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
1323 header->th_ch_flag = TH_HAS_PDU; /* Normal data */
1325 header->th_seq_num = ch->th_seq_num;
1327 CTCM_PR_DBGDATA("%s: ToVTAM_th_seq= %08x\n" ,
1328 __func__, ch->th_seq_num);
1330 memcpy(skb_push(ch->trans_skb, TH_HEADER_LENGTH), header,
1331 TH_HEADER_LENGTH); /* put the TH on the packet */
1335 CTCM_PR_DBGDATA("%s: trans_skb len:%04x \n",
1336 __func__, ch->trans_skb->len);
1337 CTCM_PR_DBGDATA("%s: up-to-50 bytes of trans_skb "
1338 "data to vtam from collect_q\n", __func__);
1339 CTCM_D3_DUMP((char *)ch->trans_skb->data,
1340 min_t(int, ch->trans_skb->len, 50));
1342 spin_unlock(&ch->collect_lock);
1343 clear_normalized_cda(&ch->ccw[1]);
1344 if (set_normalized_cda(&ch->ccw[1], ch->trans_skb->data)) {
1345 dev_kfree_skb_any(ch->trans_skb);
1346 ch->trans_skb = NULL;
1347 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR,
1348 "%s: %s: IDAL alloc failed",
1349 CTCM_FUNTAIL, ch->id);
1350 fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
1353 ch->ccw[1].count = ch->trans_skb->len;
1354 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
1355 ch->prof.send_stamp = current_kernel_time(); /* xtime */
1357 ctcmpc_dumpit((char *)&ch->ccw[0], sizeof(struct ccw1) * 3);
1358 rc = ccw_device_start(ch->cdev, &ch->ccw[0],
1359 (unsigned long)ch, 0xff, 0);
1360 ch->prof.doios_multi++;
1362 priv->stats.tx_dropped += i;
1363 priv->stats.tx_errors += i;
1364 fsm_deltimer(&ch->timer);
1365 ctcm_ccw_check_rc(ch, rc, "chained TX");
1368 ctcm_clear_busy(dev);
1373 * Got normal data, check for sanity, queue it up, allocate new buffer
1374 * trigger bottom half, and initiate next read.
1376 * fi An instance of a channel statemachine.
1377 * event The event, just happened.
1378 * arg Generic pointer, casted from channel * upon call.
1380 static void ctcmpc_chx_rx(fsm_instance *fi, int event, void *arg)
1382 struct channel *ch = arg;
1383 struct net_device *dev = ch->netdev;
1384 struct ctcm_priv *priv = dev->ml_priv;
1385 struct mpc_group *grp = priv->mpcg;
1386 struct sk_buff *skb = ch->trans_skb;
1387 struct sk_buff *new_skb;
1388 unsigned long saveflags = 0; /* avoids compiler warning */
1389 int len = ch->max_bufsize - ch->irb->scsw.cmd.count;
1391 CTCM_PR_DEBUG("%s: %s: cp:%i %s maxbuf : %04x, len: %04x\n",
1392 CTCM_FUNTAIL, dev->name, smp_processor_id(),
1393 ch->id, ch->max_bufsize, len);
1394 fsm_deltimer(&ch->timer);
1397 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1398 "%s(%s): TRANS_SKB = NULL",
1399 CTCM_FUNTAIL, dev->name);
1403 if (len < TH_HEADER_LENGTH) {
1404 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1405 "%s(%s): packet length %d to short",
1406 CTCM_FUNTAIL, dev->name, len);
1407 priv->stats.rx_dropped++;
1408 priv->stats.rx_length_errors++;
1410 /* must have valid th header or game over */
1411 __u32 block_len = len;
1412 len = TH_HEADER_LENGTH + XID2_LENGTH + 4;
1413 new_skb = __dev_alloc_skb(ch->max_bufsize, GFP_ATOMIC);
1415 if (new_skb == NULL) {
1416 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1417 "%s(%d): skb allocation failed",
1418 CTCM_FUNTAIL, dev->name);
1419 fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
1422 switch (fsm_getstate(grp->fsm)) {
1423 case MPCG_STATE_RESET:
1424 case MPCG_STATE_INOP:
1425 dev_kfree_skb_any(new_skb);
1427 case MPCG_STATE_FLOWC:
1428 case MPCG_STATE_READY:
1429 memcpy(skb_put(new_skb, block_len),
1430 skb->data, block_len);
1431 skb_queue_tail(&ch->io_queue, new_skb);
1432 tasklet_schedule(&ch->ch_tasklet);
1435 memcpy(skb_put(new_skb, len), skb->data, len);
1436 skb_queue_tail(&ch->io_queue, new_skb);
1437 tasklet_hi_schedule(&ch->ch_tasklet);
1443 switch (fsm_getstate(grp->fsm)) {
1445 case MPCG_STATE_FLOWC:
1446 case MPCG_STATE_READY:
1447 if (ctcm_checkalloc_buffer(ch))
1449 ch->trans_skb->data = ch->trans_skb_data;
1450 skb_reset_tail_pointer(ch->trans_skb);
1451 ch->trans_skb->len = 0;
1452 ch->ccw[1].count = ch->max_bufsize;
1454 ctcmpc_dumpit((char *)&ch->ccw[0],
1455 sizeof(struct ccw1) * 3);
1459 get_ccwdev_lock(ch->cdev), saveflags);
1460 rc = ccw_device_start(ch->cdev, &ch->ccw[0],
1461 (unsigned long)ch, 0xff, 0);
1462 if (dolock) /* see remark about conditional locking */
1463 spin_unlock_irqrestore(
1464 get_ccwdev_lock(ch->cdev), saveflags);
1466 ctcm_ccw_check_rc(ch, rc, "normal RX");
1471 CTCM_PR_DEBUG("Exit %s: %s, ch=0x%p, id=%s\n",
1472 __func__, dev->name, ch, ch->id);
1477 * Initialize connection by sending a __u16 of value 0.
1479 * fi An instance of a channel statemachine.
1480 * event The event, just happened.
1481 * arg Generic pointer, casted from channel * upon call.
1483 static void ctcmpc_chx_firstio(fsm_instance *fi, int event, void *arg)
1485 struct channel *ch = arg;
1486 struct net_device *dev = ch->netdev;
1487 struct ctcm_priv *priv = dev->ml_priv;
1488 struct mpc_group *gptr = priv->mpcg;
1490 CTCM_PR_DEBUG("Enter %s: id=%s, ch=0x%p\n",
1491 __func__, ch->id, ch);
1493 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_INFO,
1494 "%s: %s: chstate:%i, grpstate:%i, prot:%i\n",
1495 CTCM_FUNTAIL, ch->id, fsm_getstate(fi),
1496 fsm_getstate(gptr->fsm), ch->protocol);
1498 if (fsm_getstate(fi) == CTC_STATE_TXIDLE)
1499 MPC_DBF_DEV_NAME(TRACE, dev, "remote side issued READ? ");
1501 fsm_deltimer(&ch->timer);
1502 if (ctcm_checkalloc_buffer(ch))
1505 switch (fsm_getstate(fi)) {
1506 case CTC_STATE_STARTRETRY:
1507 case CTC_STATE_SETUPWAIT:
1508 if (CHANNEL_DIRECTION(ch->flags) == READ) {
1509 ctcmpc_chx_rxidle(fi, event, arg);
1511 fsm_newstate(fi, CTC_STATE_TXIDLE);
1512 fsm_event(priv->fsm, DEV_EVENT_TXUP, dev);
1519 fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == READ)
1520 ? CTC_STATE_RXINIT : CTC_STATE_TXINIT);
1523 CTCM_PR_DEBUG("Exit %s: id=%s, ch=0x%p\n",
1524 __func__, ch->id, ch);
1529 * Got initial data, check it. If OK,
1530 * notify device statemachine that we are up and
1533 * fi An instance of a channel statemachine.
1534 * event The event, just happened.
1535 * arg Generic pointer, casted from channel * upon call.
1537 void ctcmpc_chx_rxidle(fsm_instance *fi, int event, void *arg)
1539 struct channel *ch = arg;
1540 struct net_device *dev = ch->netdev;
1541 struct ctcm_priv *priv = dev->ml_priv;
1542 struct mpc_group *grp = priv->mpcg;
1544 unsigned long saveflags = 0; /* avoids compiler warning */
1546 fsm_deltimer(&ch->timer);
1547 CTCM_PR_DEBUG("%s: %s: %s: cp:%i, chstate:%i grpstate:%i\n",
1548 __func__, ch->id, dev->name, smp_processor_id(),
1549 fsm_getstate(fi), fsm_getstate(grp->fsm));
1551 fsm_newstate(fi, CTC_STATE_RXIDLE);
1552 /* XID processing complete */
1554 switch (fsm_getstate(grp->fsm)) {
1555 case MPCG_STATE_FLOWC:
1556 case MPCG_STATE_READY:
1557 if (ctcm_checkalloc_buffer(ch))
1559 ch->trans_skb->data = ch->trans_skb_data;
1560 skb_reset_tail_pointer(ch->trans_skb);
1561 ch->trans_skb->len = 0;
1562 ch->ccw[1].count = ch->max_bufsize;
1563 CTCM_CCW_DUMP((char *)&ch->ccw[0], sizeof(struct ccw1) * 3);
1564 if (event == CTC_EVENT_START)
1565 /* see remark about conditional locking */
1566 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1567 rc = ccw_device_start(ch->cdev, &ch->ccw[0],
1568 (unsigned long)ch, 0xff, 0);
1569 if (event == CTC_EVENT_START)
1570 spin_unlock_irqrestore(
1571 get_ccwdev_lock(ch->cdev), saveflags);
1573 fsm_newstate(fi, CTC_STATE_RXINIT);
1574 ctcm_ccw_check_rc(ch, rc, "initial RX");
1582 fsm_event(priv->fsm, DEV_EVENT_RXUP, dev);
1588 * ctcmpc channel FSM action
1589 * called from several points in ctcmpc_ch_fsm
1592 static void ctcmpc_chx_attn(fsm_instance *fsm, int event, void *arg)
1594 struct channel *ch = arg;
1595 struct net_device *dev = ch->netdev;
1596 struct ctcm_priv *priv = dev->ml_priv;
1597 struct mpc_group *grp = priv->mpcg;
1599 CTCM_PR_DEBUG("%s(%s): %s(ch=0x%p), cp=%i, ChStat:%s, GrpStat:%s\n",
1600 __func__, dev->name, ch->id, ch, smp_processor_id(),
1601 fsm_getstate_str(ch->fsm), fsm_getstate_str(grp->fsm));
1603 switch (fsm_getstate(grp->fsm)) {
1604 case MPCG_STATE_XID2INITW:
1605 /* ok..start yside xid exchanges */
1606 if (!ch->in_mpcgroup)
1608 if (fsm_getstate(ch->fsm) == CH_XID0_PENDING) {
1609 fsm_deltimer(&grp->timer);
1610 fsm_addtimer(&grp->timer,
1611 MPC_XID_TIMEOUT_VALUE,
1612 MPCG_EVENT_TIMER, dev);
1613 fsm_event(grp->fsm, MPCG_EVENT_XID0DO, ch);
1615 } else if (fsm_getstate(ch->fsm) < CH_XID7_PENDING1)
1616 /* attn rcvd before xid0 processed via bh */
1617 fsm_newstate(ch->fsm, CH_XID7_PENDING1);
1619 case MPCG_STATE_XID2INITX:
1620 case MPCG_STATE_XID0IOWAIT:
1621 case MPCG_STATE_XID0IOWAIX:
1622 /* attn rcvd before xid0 processed on ch
1623 but mid-xid0 processing for group */
1624 if (fsm_getstate(ch->fsm) < CH_XID7_PENDING1)
1625 fsm_newstate(ch->fsm, CH_XID7_PENDING1);
1627 case MPCG_STATE_XID7INITW:
1628 case MPCG_STATE_XID7INITX:
1629 case MPCG_STATE_XID7INITI:
1630 case MPCG_STATE_XID7INITZ:
1631 switch (fsm_getstate(ch->fsm)) {
1632 case CH_XID7_PENDING:
1633 fsm_newstate(ch->fsm, CH_XID7_PENDING1);
1635 case CH_XID7_PENDING2:
1636 fsm_newstate(ch->fsm, CH_XID7_PENDING3);
1639 fsm_event(grp->fsm, MPCG_EVENT_XID7DONE, dev);
1647 * ctcmpc channel FSM action
1648 * called from one point in ctcmpc_ch_fsm
1651 static void ctcmpc_chx_attnbusy(fsm_instance *fsm, int event, void *arg)
1653 struct channel *ch = arg;
1654 struct net_device *dev = ch->netdev;
1655 struct ctcm_priv *priv = dev->ml_priv;
1656 struct mpc_group *grp = priv->mpcg;
1658 CTCM_PR_DEBUG("%s(%s): %s\n ChState:%s GrpState:%s\n",
1659 __func__, dev->name, ch->id,
1660 fsm_getstate_str(ch->fsm), fsm_getstate_str(grp->fsm));
1662 fsm_deltimer(&ch->timer);
1664 switch (fsm_getstate(grp->fsm)) {
1665 case MPCG_STATE_XID0IOWAIT:
1666 /* vtam wants to be primary.start yside xid exchanges*/
1667 /* only receive one attn-busy at a time so must not */
1668 /* change state each time */
1669 grp->changed_side = 1;
1670 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);
1672 case MPCG_STATE_XID2INITW:
1673 if (grp->changed_side == 1) {
1674 grp->changed_side = 2;
1677 /* process began via call to establish_conn */
1678 /* so must report failure instead of reverting */
1679 /* back to ready-for-xid passive state */
1680 if (grp->estconnfunc)
1682 /* this attnbusy is NOT the result of xside xid */
1683 /* collisions so yside must have been triggered */
1684 /* by an ATTN that was not intended to start XID */
1685 /* processing. Revert back to ready-for-xid and */
1686 /* wait for ATTN interrupt to signal xid start */
1687 if (fsm_getstate(ch->fsm) == CH_XID0_INPROGRESS) {
1688 fsm_newstate(ch->fsm, CH_XID0_PENDING) ;
1689 fsm_deltimer(&grp->timer);
1692 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1694 case MPCG_STATE_XID2INITX:
1695 /* XID2 was received before ATTN Busy for second
1696 channel.Send yside xid for second channel.
1698 if (grp->changed_side == 1) {
1699 grp->changed_side = 2;
1702 case MPCG_STATE_XID0IOWAIX:
1703 case MPCG_STATE_XID7INITW:
1704 case MPCG_STATE_XID7INITX:
1705 case MPCG_STATE_XID7INITI:
1706 case MPCG_STATE_XID7INITZ:
1708 /* multiple attn-busy indicates too out-of-sync */
1709 /* and they are certainly not being received as part */
1710 /* of valid mpc group negotiations.. */
1711 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1715 if (grp->changed_side == 1) {
1716 fsm_deltimer(&grp->timer);
1717 fsm_addtimer(&grp->timer, MPC_XID_TIMEOUT_VALUE,
1718 MPCG_EVENT_TIMER, dev);
1720 if (ch->in_mpcgroup)
1721 fsm_event(grp->fsm, MPCG_EVENT_XID0DO, ch);
1723 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1724 "%s(%s): channel %s not added to group",
1725 CTCM_FUNTAIL, dev->name, ch->id);
1732 * ctcmpc channel FSM action
1733 * called from several points in ctcmpc_ch_fsm
1736 static void ctcmpc_chx_resend(fsm_instance *fsm, int event, void *arg)
1738 struct channel *ch = arg;
1739 struct net_device *dev = ch->netdev;
1740 struct ctcm_priv *priv = dev->ml_priv;
1741 struct mpc_group *grp = priv->mpcg;
1743 fsm_event(grp->fsm, MPCG_EVENT_XID0DO, ch);
1748 * ctcmpc channel FSM action
1749 * called from several points in ctcmpc_ch_fsm
1752 static void ctcmpc_chx_send_sweep(fsm_instance *fsm, int event, void *arg)
1754 struct channel *ach = arg;
1755 struct net_device *dev = ach->netdev;
1756 struct ctcm_priv *priv = dev->ml_priv;
1757 struct mpc_group *grp = priv->mpcg;
1758 struct channel *wch = priv->channel[WRITE];
1759 struct channel *rch = priv->channel[READ];
1760 struct sk_buff *skb;
1761 struct th_sweep *header;
1763 unsigned long saveflags = 0;
1765 CTCM_PR_DEBUG("ctcmpc enter: %s(): cp=%i ch=0x%p id=%s\n",
1766 __func__, smp_processor_id(), ach, ach->id);
1768 if (grp->in_sweep == 0)
1771 CTCM_PR_DBGDATA("%s: 1: ToVTAM_th_seq= %08x\n" ,
1772 __func__, wch->th_seq_num);
1773 CTCM_PR_DBGDATA("%s: 1: FromVTAM_th_seq= %08x\n" ,
1774 __func__, rch->th_seq_num);
1776 if (fsm_getstate(wch->fsm) != CTC_STATE_TXIDLE) {
1777 /* give the previous IO time to complete */
1778 fsm_addtimer(&wch->sweep_timer,
1779 200, CTC_EVENT_RSWEEP_TIMER, wch);
1783 skb = skb_dequeue(&wch->sweep_queue);
1787 if (set_normalized_cda(&wch->ccw[4], skb->data)) {
1789 ctcm_clear_busy_do(dev);
1790 dev_kfree_skb_any(skb);
1791 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1794 atomic_inc(&skb->users);
1795 skb_queue_tail(&wch->io_queue, skb);
1798 /* send out the sweep */
1799 wch->ccw[4].count = skb->len;
1801 header = (struct th_sweep *)skb->data;
1802 switch (header->th.th_ch_flag) {
1804 grp->sweep_req_pend_num--;
1807 grp->sweep_rsp_pend_num--;
1811 header->sw.th_last_seq = wch->th_seq_num;
1813 CTCM_CCW_DUMP((char *)&wch->ccw[3], sizeof(struct ccw1) * 3);
1814 CTCM_PR_DBGDATA("%s: sweep packet\n", __func__);
1815 CTCM_D3_DUMP((char *)header, TH_SWEEP_LENGTH);
1817 fsm_addtimer(&wch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, wch);
1818 fsm_newstate(wch->fsm, CTC_STATE_TX);
1820 spin_lock_irqsave(get_ccwdev_lock(wch->cdev), saveflags);
1821 wch->prof.send_stamp = current_kernel_time(); /* xtime */
1822 rc = ccw_device_start(wch->cdev, &wch->ccw[3],
1823 (unsigned long) wch, 0xff, 0);
1824 spin_unlock_irqrestore(get_ccwdev_lock(wch->cdev), saveflags);
1826 if ((grp->sweep_req_pend_num == 0) &&
1827 (grp->sweep_rsp_pend_num == 0)) {
1829 rch->th_seq_num = 0x00;
1830 wch->th_seq_num = 0x00;
1831 ctcm_clear_busy_do(dev);
1834 CTCM_PR_DBGDATA("%s: To-/From-VTAM_th_seq = %08x/%08x\n" ,
1835 __func__, wch->th_seq_num, rch->th_seq_num);
1838 ctcm_ccw_check_rc(wch, rc, "send sweep");
1846 * The ctcmpc statemachine for a channel.
1849 const fsm_node ctcmpc_ch_fsm[] = {
1850 { CTC_STATE_STOPPED, CTC_EVENT_STOP, ctcm_action_nop },
1851 { CTC_STATE_STOPPED, CTC_EVENT_START, ctcm_chx_start },
1852 { CTC_STATE_STOPPED, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1853 { CTC_STATE_STOPPED, CTC_EVENT_FINSTAT, ctcm_action_nop },
1854 { CTC_STATE_STOPPED, CTC_EVENT_MC_FAIL, ctcm_action_nop },
1856 { CTC_STATE_NOTOP, CTC_EVENT_STOP, ctcm_chx_stop },
1857 { CTC_STATE_NOTOP, CTC_EVENT_START, ctcm_action_nop },
1858 { CTC_STATE_NOTOP, CTC_EVENT_FINSTAT, ctcm_action_nop },
1859 { CTC_STATE_NOTOP, CTC_EVENT_MC_FAIL, ctcm_action_nop },
1860 { CTC_STATE_NOTOP, CTC_EVENT_MC_GOOD, ctcm_chx_start },
1861 { CTC_STATE_NOTOP, CTC_EVENT_UC_RCRESET, ctcm_chx_stop },
1862 { CTC_STATE_NOTOP, CTC_EVENT_UC_RSRESET, ctcm_chx_stop },
1863 { CTC_STATE_NOTOP, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1865 { CTC_STATE_STARTWAIT, CTC_EVENT_STOP, ctcm_chx_haltio },
1866 { CTC_STATE_STARTWAIT, CTC_EVENT_START, ctcm_action_nop },
1867 { CTC_STATE_STARTWAIT, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
1868 { CTC_STATE_STARTWAIT, CTC_EVENT_TIMER, ctcm_chx_setuperr },
1869 { CTC_STATE_STARTWAIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1870 { CTC_STATE_STARTWAIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1872 { CTC_STATE_STARTRETRY, CTC_EVENT_STOP, ctcm_chx_haltio },
1873 { CTC_STATE_STARTRETRY, CTC_EVENT_TIMER, ctcm_chx_setmode },
1874 { CTC_STATE_STARTRETRY, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
1875 { CTC_STATE_STARTRETRY, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1876 { CTC_STATE_STARTRETRY, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1878 { CTC_STATE_SETUPWAIT, CTC_EVENT_STOP, ctcm_chx_haltio },
1879 { CTC_STATE_SETUPWAIT, CTC_EVENT_START, ctcm_action_nop },
1880 { CTC_STATE_SETUPWAIT, CTC_EVENT_FINSTAT, ctcmpc_chx_firstio },
1881 { CTC_STATE_SETUPWAIT, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
1882 { CTC_STATE_SETUPWAIT, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
1883 { CTC_STATE_SETUPWAIT, CTC_EVENT_TIMER, ctcm_chx_setmode },
1884 { CTC_STATE_SETUPWAIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1885 { CTC_STATE_SETUPWAIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1887 { CTC_STATE_RXINIT, CTC_EVENT_STOP, ctcm_chx_haltio },
1888 { CTC_STATE_RXINIT, CTC_EVENT_START, ctcm_action_nop },
1889 { CTC_STATE_RXINIT, CTC_EVENT_FINSTAT, ctcmpc_chx_rxidle },
1890 { CTC_STATE_RXINIT, CTC_EVENT_UC_RCRESET, ctcm_chx_rxiniterr },
1891 { CTC_STATE_RXINIT, CTC_EVENT_UC_RSRESET, ctcm_chx_rxiniterr },
1892 { CTC_STATE_RXINIT, CTC_EVENT_TIMER, ctcm_chx_rxiniterr },
1893 { CTC_STATE_RXINIT, CTC_EVENT_ATTNBUSY, ctcm_chx_rxinitfail },
1894 { CTC_STATE_RXINIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1895 { CTC_STATE_RXINIT, CTC_EVENT_UC_ZERO, ctcmpc_chx_firstio },
1896 { CTC_STATE_RXINIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1898 { CH_XID0_PENDING, CTC_EVENT_FINSTAT, ctcm_action_nop },
1899 { CH_XID0_PENDING, CTC_EVENT_ATTN, ctcmpc_chx_attn },
1900 { CH_XID0_PENDING, CTC_EVENT_STOP, ctcm_chx_haltio },
1901 { CH_XID0_PENDING, CTC_EVENT_START, ctcm_action_nop },
1902 { CH_XID0_PENDING, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1903 { CH_XID0_PENDING, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1904 { CH_XID0_PENDING, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
1905 { CH_XID0_PENDING, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
1906 { CH_XID0_PENDING, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
1907 { CH_XID0_PENDING, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
1909 { CH_XID0_INPROGRESS, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
1910 { CH_XID0_INPROGRESS, CTC_EVENT_ATTN, ctcmpc_chx_attn },
1911 { CH_XID0_INPROGRESS, CTC_EVENT_STOP, ctcm_chx_haltio },
1912 { CH_XID0_INPROGRESS, CTC_EVENT_START, ctcm_action_nop },
1913 { CH_XID0_INPROGRESS, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1914 { CH_XID0_INPROGRESS, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1915 { CH_XID0_INPROGRESS, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
1916 { CH_XID0_INPROGRESS, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
1917 { CH_XID0_INPROGRESS, CTC_EVENT_ATTNBUSY, ctcmpc_chx_attnbusy },
1918 { CH_XID0_INPROGRESS, CTC_EVENT_TIMER, ctcmpc_chx_resend },
1919 { CH_XID0_INPROGRESS, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
1921 { CH_XID7_PENDING, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
1922 { CH_XID7_PENDING, CTC_EVENT_ATTN, ctcmpc_chx_attn },
1923 { CH_XID7_PENDING, CTC_EVENT_STOP, ctcm_chx_haltio },
1924 { CH_XID7_PENDING, CTC_EVENT_START, ctcm_action_nop },
1925 { CH_XID7_PENDING, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1926 { CH_XID7_PENDING, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1927 { CH_XID7_PENDING, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
1928 { CH_XID7_PENDING, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
1929 { CH_XID7_PENDING, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
1930 { CH_XID7_PENDING, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
1931 { CH_XID7_PENDING, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
1932 { CH_XID7_PENDING, CTC_EVENT_TIMER, ctcmpc_chx_resend },
1933 { CH_XID7_PENDING, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
1935 { CH_XID7_PENDING1, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
1936 { CH_XID7_PENDING1, CTC_EVENT_ATTN, ctcmpc_chx_attn },
1937 { CH_XID7_PENDING1, CTC_EVENT_STOP, ctcm_chx_haltio },
1938 { CH_XID7_PENDING1, CTC_EVENT_START, ctcm_action_nop },
1939 { CH_XID7_PENDING1, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1940 { CH_XID7_PENDING1, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1941 { CH_XID7_PENDING1, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
1942 { CH_XID7_PENDING1, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
1943 { CH_XID7_PENDING1, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
1944 { CH_XID7_PENDING1, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
1945 { CH_XID7_PENDING1, CTC_EVENT_TIMER, ctcmpc_chx_resend },
1946 { CH_XID7_PENDING1, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
1948 { CH_XID7_PENDING2, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
1949 { CH_XID7_PENDING2, CTC_EVENT_ATTN, ctcmpc_chx_attn },
1950 { CH_XID7_PENDING2, CTC_EVENT_STOP, ctcm_chx_haltio },
1951 { CH_XID7_PENDING2, CTC_EVENT_START, ctcm_action_nop },
1952 { CH_XID7_PENDING2, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1953 { CH_XID7_PENDING2, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1954 { CH_XID7_PENDING2, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
1955 { CH_XID7_PENDING2, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
1956 { CH_XID7_PENDING2, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
1957 { CH_XID7_PENDING2, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
1958 { CH_XID7_PENDING2, CTC_EVENT_TIMER, ctcmpc_chx_resend },
1959 { CH_XID7_PENDING2, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
1961 { CH_XID7_PENDING3, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
1962 { CH_XID7_PENDING3, CTC_EVENT_ATTN, ctcmpc_chx_attn },
1963 { CH_XID7_PENDING3, CTC_EVENT_STOP, ctcm_chx_haltio },
1964 { CH_XID7_PENDING3, CTC_EVENT_START, ctcm_action_nop },
1965 { CH_XID7_PENDING3, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1966 { CH_XID7_PENDING3, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1967 { CH_XID7_PENDING3, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
1968 { CH_XID7_PENDING3, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
1969 { CH_XID7_PENDING3, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
1970 { CH_XID7_PENDING3, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
1971 { CH_XID7_PENDING3, CTC_EVENT_TIMER, ctcmpc_chx_resend },
1972 { CH_XID7_PENDING3, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
1974 { CH_XID7_PENDING4, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
1975 { CH_XID7_PENDING4, CTC_EVENT_ATTN, ctcmpc_chx_attn },
1976 { CH_XID7_PENDING4, CTC_EVENT_STOP, ctcm_chx_haltio },
1977 { CH_XID7_PENDING4, CTC_EVENT_START, ctcm_action_nop },
1978 { CH_XID7_PENDING4, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1979 { CH_XID7_PENDING4, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1980 { CH_XID7_PENDING4, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
1981 { CH_XID7_PENDING4, CTC_EVENT_UC_RCRESET, ctcm_chx_setuperr },
1982 { CH_XID7_PENDING4, CTC_EVENT_UC_RSRESET, ctcm_chx_setuperr },
1983 { CH_XID7_PENDING4, CTC_EVENT_ATTNBUSY, ctcm_chx_iofatal },
1984 { CH_XID7_PENDING4, CTC_EVENT_TIMER, ctcmpc_chx_resend },
1985 { CH_XID7_PENDING4, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
1987 { CTC_STATE_RXIDLE, CTC_EVENT_STOP, ctcm_chx_haltio },
1988 { CTC_STATE_RXIDLE, CTC_EVENT_START, ctcm_action_nop },
1989 { CTC_STATE_RXIDLE, CTC_EVENT_FINSTAT, ctcmpc_chx_rx },
1990 { CTC_STATE_RXIDLE, CTC_EVENT_UC_RCRESET, ctcm_chx_rxdisc },
1991 { CTC_STATE_RXIDLE, CTC_EVENT_UC_RSRESET, ctcm_chx_fail },
1992 { CTC_STATE_RXIDLE, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
1993 { CTC_STATE_RXIDLE, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
1994 { CTC_STATE_RXIDLE, CTC_EVENT_UC_ZERO, ctcmpc_chx_rx },
1996 { CTC_STATE_TXINIT, CTC_EVENT_STOP, ctcm_chx_haltio },
1997 { CTC_STATE_TXINIT, CTC_EVENT_START, ctcm_action_nop },
1998 { CTC_STATE_TXINIT, CTC_EVENT_FINSTAT, ctcm_chx_txidle },
1999 { CTC_STATE_TXINIT, CTC_EVENT_UC_RCRESET, ctcm_chx_txiniterr },
2000 { CTC_STATE_TXINIT, CTC_EVENT_UC_RSRESET, ctcm_chx_txiniterr },
2001 { CTC_STATE_TXINIT, CTC_EVENT_TIMER, ctcm_chx_txiniterr },
2002 { CTC_STATE_TXINIT, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
2003 { CTC_STATE_TXINIT, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
2004 { CTC_STATE_TXINIT, CTC_EVENT_RSWEEP_TIMER, ctcmpc_chx_send_sweep },
2006 { CTC_STATE_TXIDLE, CTC_EVENT_STOP, ctcm_chx_haltio },
2007 { CTC_STATE_TXIDLE, CTC_EVENT_START, ctcm_action_nop },
2008 { CTC_STATE_TXIDLE, CTC_EVENT_FINSTAT, ctcmpc_chx_firstio },
2009 { CTC_STATE_TXIDLE, CTC_EVENT_UC_RCRESET, ctcm_chx_fail },
2010 { CTC_STATE_TXIDLE, CTC_EVENT_UC_RSRESET, ctcm_chx_fail },
2011 { CTC_STATE_TXIDLE, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
2012 { CTC_STATE_TXIDLE, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
2013 { CTC_STATE_TXIDLE, CTC_EVENT_RSWEEP_TIMER, ctcmpc_chx_send_sweep },
2015 { CTC_STATE_TERM, CTC_EVENT_STOP, ctcm_action_nop },
2016 { CTC_STATE_TERM, CTC_EVENT_START, ctcm_chx_restart },
2017 { CTC_STATE_TERM, CTC_EVENT_FINSTAT, ctcm_chx_stopped },
2018 { CTC_STATE_TERM, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
2019 { CTC_STATE_TERM, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
2020 { CTC_STATE_TERM, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
2021 { CTC_STATE_TERM, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
2022 { CTC_STATE_TERM, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
2024 { CTC_STATE_DTERM, CTC_EVENT_STOP, ctcm_chx_haltio },
2025 { CTC_STATE_DTERM, CTC_EVENT_START, ctcm_chx_restart },
2026 { CTC_STATE_DTERM, CTC_EVENT_FINSTAT, ctcm_chx_setmode },
2027 { CTC_STATE_DTERM, CTC_EVENT_UC_RCRESET, ctcm_action_nop },
2028 { CTC_STATE_DTERM, CTC_EVENT_UC_RSRESET, ctcm_action_nop },
2029 { CTC_STATE_DTERM, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
2030 { CTC_STATE_DTERM, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
2032 { CTC_STATE_TX, CTC_EVENT_STOP, ctcm_chx_haltio },
2033 { CTC_STATE_TX, CTC_EVENT_START, ctcm_action_nop },
2034 { CTC_STATE_TX, CTC_EVENT_FINSTAT, ctcmpc_chx_txdone },
2035 { CTC_STATE_TX, CTC_EVENT_UC_RCRESET, ctcm_chx_fail },
2036 { CTC_STATE_TX, CTC_EVENT_UC_RSRESET, ctcm_chx_fail },
2037 { CTC_STATE_TX, CTC_EVENT_TIMER, ctcm_chx_txretry },
2038 { CTC_STATE_TX, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
2039 { CTC_STATE_TX, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
2040 { CTC_STATE_TX, CTC_EVENT_RSWEEP_TIMER, ctcmpc_chx_send_sweep },
2041 { CTC_STATE_TX, CTC_EVENT_IO_EBUSY, ctcm_chx_fail },
2043 { CTC_STATE_RXERR, CTC_EVENT_STOP, ctcm_chx_haltio },
2044 { CTC_STATE_TXERR, CTC_EVENT_STOP, ctcm_chx_haltio },
2045 { CTC_STATE_TXERR, CTC_EVENT_IO_ENODEV, ctcm_chx_iofatal },
2046 { CTC_STATE_TXERR, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
2047 { CTC_STATE_RXERR, CTC_EVENT_MC_FAIL, ctcm_chx_fail },
2050 int mpc_ch_fsm_len = ARRAY_SIZE(ctcmpc_ch_fsm);
2053 * Actions for interface - statemachine.
2057 * Startup channels by sending CTC_EVENT_START to each channel.
2059 * fi An instance of an interface statemachine.
2060 * event The event, just happened.
2061 * arg Generic pointer, casted from struct net_device * upon call.
2063 static void dev_action_start(fsm_instance *fi, int event, void *arg)
2065 struct net_device *dev = arg;
2066 struct ctcm_priv *priv = dev->ml_priv;
2069 CTCMY_DBF_DEV_NAME(SETUP, dev, "");
2071 fsm_deltimer(&priv->restart_timer);
2072 fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
2074 priv->mpcg->channels_terminating = 0;
2075 for (direction = READ; direction <= WRITE; direction++) {
2076 struct channel *ch = priv->channel[direction];
2077 fsm_event(ch->fsm, CTC_EVENT_START, ch);
2082 * Shutdown channels by sending CTC_EVENT_STOP to each channel.
2084 * fi An instance of an interface statemachine.
2085 * event The event, just happened.
2086 * arg Generic pointer, casted from struct net_device * upon call.
2088 static void dev_action_stop(fsm_instance *fi, int event, void *arg)
2091 struct net_device *dev = arg;
2092 struct ctcm_priv *priv = dev->ml_priv;
2094 CTCMY_DBF_DEV_NAME(SETUP, dev, "");
2096 fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
2097 for (direction = READ; direction <= WRITE; direction++) {
2098 struct channel *ch = priv->channel[direction];
2099 fsm_event(ch->fsm, CTC_EVENT_STOP, ch);
2100 ch->th_seq_num = 0x00;
2101 CTCM_PR_DEBUG("%s: CH_th_seq= %08x\n",
2102 __func__, ch->th_seq_num);
2105 fsm_newstate(priv->mpcg->fsm, MPCG_STATE_RESET);
2108 static void dev_action_restart(fsm_instance *fi, int event, void *arg)
2111 struct net_device *dev = arg;
2112 struct ctcm_priv *priv = dev->ml_priv;
2114 CTCMY_DBF_DEV_NAME(TRACE, dev, "");
2117 restart_timer = CTCM_TIME_1_SEC;
2119 restart_timer = CTCM_TIME_5_SEC;
2121 dev_info(&dev->dev, "Restarting device\n");
2123 dev_action_stop(fi, event, arg);
2124 fsm_event(priv->fsm, DEV_EVENT_STOP, dev);
2126 fsm_newstate(priv->mpcg->fsm, MPCG_STATE_RESET);
2128 /* going back into start sequence too quickly can */
2129 /* result in the other side becoming unreachable due */
2130 /* to sense reported when IO is aborted */
2131 fsm_addtimer(&priv->restart_timer, restart_timer,
2132 DEV_EVENT_START, dev);
2136 * Called from channel statemachine
2137 * when a channel is up and running.
2139 * fi An instance of an interface statemachine.
2140 * event The event, just happened.
2141 * arg Generic pointer, casted from struct net_device * upon call.
2143 static void dev_action_chup(fsm_instance *fi, int event, void *arg)
2145 struct net_device *dev = arg;
2146 struct ctcm_priv *priv = dev->ml_priv;
2147 int dev_stat = fsm_getstate(fi);
2149 CTCM_DBF_TEXT_(SETUP, CTC_DBF_NOTICE,
2150 "%s(%s): priv = %p [%d,%d]\n ", CTCM_FUNTAIL,
2151 dev->name, dev->ml_priv, dev_stat, event);
2153 switch (fsm_getstate(fi)) {
2154 case DEV_STATE_STARTWAIT_RXTX:
2155 if (event == DEV_EVENT_RXUP)
2156 fsm_newstate(fi, DEV_STATE_STARTWAIT_TX);
2158 fsm_newstate(fi, DEV_STATE_STARTWAIT_RX);
2160 case DEV_STATE_STARTWAIT_RX:
2161 if (event == DEV_EVENT_RXUP) {
2162 fsm_newstate(fi, DEV_STATE_RUNNING);
2164 "Connected with remote side\n");
2165 ctcm_clear_busy(dev);
2168 case DEV_STATE_STARTWAIT_TX:
2169 if (event == DEV_EVENT_TXUP) {
2170 fsm_newstate(fi, DEV_STATE_RUNNING);
2172 "Connected with remote side\n");
2173 ctcm_clear_busy(dev);
2176 case DEV_STATE_STOPWAIT_TX:
2177 if (event == DEV_EVENT_RXUP)
2178 fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
2180 case DEV_STATE_STOPWAIT_RX:
2181 if (event == DEV_EVENT_TXUP)
2182 fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
2187 if (event == DEV_EVENT_RXUP)
2188 mpc_channel_action(priv->channel[READ],
2189 READ, MPC_CHANNEL_ADD);
2191 mpc_channel_action(priv->channel[WRITE],
2192 WRITE, MPC_CHANNEL_ADD);
2197 * Called from device statemachine
2198 * when a channel has been shutdown.
2200 * fi An instance of an interface statemachine.
2201 * event The event, just happened.
2202 * arg Generic pointer, casted from struct net_device * upon call.
2204 static void dev_action_chdown(fsm_instance *fi, int event, void *arg)
2207 struct net_device *dev = arg;
2208 struct ctcm_priv *priv = dev->ml_priv;
2210 CTCMY_DBF_DEV_NAME(SETUP, dev, "");
2212 switch (fsm_getstate(fi)) {
2213 case DEV_STATE_RUNNING:
2214 if (event == DEV_EVENT_TXDOWN)
2215 fsm_newstate(fi, DEV_STATE_STARTWAIT_TX);
2217 fsm_newstate(fi, DEV_STATE_STARTWAIT_RX);
2219 case DEV_STATE_STARTWAIT_RX:
2220 if (event == DEV_EVENT_TXDOWN)
2221 fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
2223 case DEV_STATE_STARTWAIT_TX:
2224 if (event == DEV_EVENT_RXDOWN)
2225 fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
2227 case DEV_STATE_STOPWAIT_RXTX:
2228 if (event == DEV_EVENT_TXDOWN)
2229 fsm_newstate(fi, DEV_STATE_STOPWAIT_RX);
2231 fsm_newstate(fi, DEV_STATE_STOPWAIT_TX);
2233 case DEV_STATE_STOPWAIT_RX:
2234 if (event == DEV_EVENT_RXDOWN)
2235 fsm_newstate(fi, DEV_STATE_STOPPED);
2237 case DEV_STATE_STOPWAIT_TX:
2238 if (event == DEV_EVENT_TXDOWN)
2239 fsm_newstate(fi, DEV_STATE_STOPPED);
2243 if (event == DEV_EVENT_RXDOWN)
2244 mpc_channel_action(priv->channel[READ],
2245 READ, MPC_CHANNEL_REMOVE);
2247 mpc_channel_action(priv->channel[WRITE],
2248 WRITE, MPC_CHANNEL_REMOVE);
2252 const fsm_node dev_fsm[] = {
2253 { DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start },
2254 { DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_START, dev_action_start },
2255 { DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_RXDOWN, dev_action_chdown },
2256 { DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_TXDOWN, dev_action_chdown },
2257 { DEV_STATE_STOPWAIT_RXTX, DEV_EVENT_RESTART, dev_action_restart },
2258 { DEV_STATE_STOPWAIT_RX, DEV_EVENT_START, dev_action_start },
2259 { DEV_STATE_STOPWAIT_RX, DEV_EVENT_RXUP, dev_action_chup },
2260 { DEV_STATE_STOPWAIT_RX, DEV_EVENT_TXUP, dev_action_chup },
2261 { DEV_STATE_STOPWAIT_RX, DEV_EVENT_RXDOWN, dev_action_chdown },
2262 { DEV_STATE_STOPWAIT_RX, DEV_EVENT_RESTART, dev_action_restart },
2263 { DEV_STATE_STOPWAIT_TX, DEV_EVENT_START, dev_action_start },
2264 { DEV_STATE_STOPWAIT_TX, DEV_EVENT_RXUP, dev_action_chup },
2265 { DEV_STATE_STOPWAIT_TX, DEV_EVENT_TXUP, dev_action_chup },
2266 { DEV_STATE_STOPWAIT_TX, DEV_EVENT_TXDOWN, dev_action_chdown },
2267 { DEV_STATE_STOPWAIT_TX, DEV_EVENT_RESTART, dev_action_restart },
2268 { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_STOP, dev_action_stop },
2269 { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RXUP, dev_action_chup },
2270 { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_TXUP, dev_action_chup },
2271 { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RXDOWN, dev_action_chdown },
2272 { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_TXDOWN, dev_action_chdown },
2273 { DEV_STATE_STARTWAIT_RXTX, DEV_EVENT_RESTART, dev_action_restart },
2274 { DEV_STATE_STARTWAIT_TX, DEV_EVENT_STOP, dev_action_stop },
2275 { DEV_STATE_STARTWAIT_TX, DEV_EVENT_RXUP, dev_action_chup },
2276 { DEV_STATE_STARTWAIT_TX, DEV_EVENT_TXUP, dev_action_chup },
2277 { DEV_STATE_STARTWAIT_TX, DEV_EVENT_RXDOWN, dev_action_chdown },
2278 { DEV_STATE_STARTWAIT_TX, DEV_EVENT_RESTART, dev_action_restart },
2279 { DEV_STATE_STARTWAIT_RX, DEV_EVENT_STOP, dev_action_stop },
2280 { DEV_STATE_STARTWAIT_RX, DEV_EVENT_RXUP, dev_action_chup },
2281 { DEV_STATE_STARTWAIT_RX, DEV_EVENT_TXUP, dev_action_chup },
2282 { DEV_STATE_STARTWAIT_RX, DEV_EVENT_TXDOWN, dev_action_chdown },
2283 { DEV_STATE_STARTWAIT_RX, DEV_EVENT_RESTART, dev_action_restart },
2284 { DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop },
2285 { DEV_STATE_RUNNING, DEV_EVENT_RXDOWN, dev_action_chdown },
2286 { DEV_STATE_RUNNING, DEV_EVENT_TXDOWN, dev_action_chdown },
2287 { DEV_STATE_RUNNING, DEV_EVENT_TXUP, ctcm_action_nop },
2288 { DEV_STATE_RUNNING, DEV_EVENT_RXUP, ctcm_action_nop },
2289 { DEV_STATE_RUNNING, DEV_EVENT_RESTART, dev_action_restart },
2292 int dev_fsm_len = ARRAY_SIZE(dev_fsm);
2294 /* --- This is the END my friend --- */