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