14 #define KMSG_COMPONENT "ctcm"
15 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
17 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/slab.h>
21 #include <linux/errno.h>
22 #include <linux/types.h>
25 #include <linux/bitops.h>
27 #include <linux/signal.h>
28 #include <linux/string.h>
31 #include <linux/if_arp.h>
32 #include <linux/tcp.h>
34 #include <linux/ctype.h>
180 static void ctcmpc_chx_attnbusy(
fsm_instance *,
int,
void *);
181 static void ctcmpc_chx_resend(
fsm_instance *,
int,
void *);
193 "%s(%s): %s: %04x\n",
197 pr_info(
"%s: The communication peer is busy\n",
202 pr_err(
"%s: The specified target device is not valid\n",
207 pr_err(
"An I/O operation resulted in error %04x\n",
259 (done_stamp.
tv_sec - ch->
prof.send_stamp.tv_sec) * 1000000 +
260 (done_stamp.
tv_nsec - ch->
prof.send_stamp.tv_nsec) / 1000;
261 if (duration > ch->
prof.tx_time)
264 if (ch->
irb->scsw.cmd.count != 0)
266 "%s(%s): TX not complete, remaining %d bytes",
270 priv->
stats.tx_packets++;
273 priv->
stats.tx_bytes += 2;
280 clear_normalized_cda(&ch->
ccw[4]);
284 if (ctcm_checkalloc_buffer(ch)) {
298 skb_copy_from_linear_data(skb,
300 priv->
stats.tx_packets++;
312 (
unsigned long)ch, 0xff, 0);
313 ch->
prof.doios_multi++;
315 priv->
stats.tx_dropped +=
i;
316 priv->
stats.tx_errors +=
i;
324 ctcm_clear_busy_do(dev);
357 static void chx_rx(
fsm_instance *fi,
int event,
void *arg)
371 "%s(%s): got packet with length %d < 8\n",
373 priv->
stats.rx_dropped++;
374 priv->
stats.rx_length_errors++;
379 "%s(%s): got packet with length %d > %d\n",
381 priv->
stats.rx_dropped++;
382 priv->
stats.rx_length_errors++;
392 check_len = block_len + 2;
395 check_len = block_len;
398 if ((len < block_len) || (len > check_len)) {
400 "%s(%s): got block length %d != rx length %d\n",
403 ctcmpc_dump_skb(skb, 0);
406 priv->
stats.rx_dropped++;
407 priv->
stats.rx_length_errors++;
416 skb_reset_tail_pointer(skb);
418 if (ctcm_checkalloc_buffer(ch))
422 (
unsigned long)ch, 0xff, 0);
434 static void chx_firstio(
fsm_instance *fi,
int event,
void *arg)
438 int fsmstate = fsm_getstate(fi);
447 "%s(%s): remote side issued READ?, init.\n",
450 if (ctcm_checkalloc_buffer(ch))
459 chx_rxidle(fi, event, arg);
478 ch->
ccw[1].count = 2;
483 (
unsigned long)ch, 0xff, 0);
513 static void chx_rxidle(
fsm_instance *fi,
int event,
void *arg)
524 __func__, dev->
name, buflen);
527 if (ctcm_checkalloc_buffer(ch))
532 (
unsigned long)ch, 0xff, 0);
542 chx_firstio(fi, event, arg);
553 static void ctcm_chx_setmode(
fsm_instance *fi,
int event,
void *arg)
557 unsigned long saveflags = 0;
576 (
unsigned long)ch, 0xff, 0);
594 static void ctcm_chx_start(
fsm_instance *fi,
int event,
void *arg)
597 unsigned long saveflags;
605 clear_normalized_cda(&ch->
ccw[1]);
612 ch->
ccw[1].count = 0;
616 ch->
ccw[1].count = 0;
618 if (ctcm_checkalloc_buffer(ch)) {
620 "%s(%s): %s trans_skb alloc delayed "
621 "until first transfer",
628 ch->
ccw[0].count = 0;
632 ch->
ccw[2].count = 0;
657 static void ctcm_chx_haltio(
fsm_instance *fi,
int event,
void *arg)
660 unsigned long saveflags = 0;
674 oldstate = fsm_getstate(fi);
682 if (rc != 0 && rc != -
EBUSY) {
685 fsm_newstate(fi, oldstate);
713 fsm_newstate(fi, state);
715 clear_normalized_cda(&ch->
ccw[1]);
745 static void ctcm_chx_stopped(
fsm_instance *fi,
int event,
void *arg)
758 static void ctcm_chx_stop(
fsm_instance *fi,
int event,
void *arg)
772 static void ctcm_chx_fail(
fsm_instance *fi,
int event,
void *arg)
784 static void ctcm_chx_setuperr(
fsm_instance *fi,
int event,
void *arg)
806 "HaltIO in chx_setuperr");
812 "%s(%s) : %s error during %s channel setup state=%s\n",
833 static void ctcm_chx_restart(
fsm_instance *fi,
int event,
void *arg)
837 unsigned long saveflags = 0;
842 "%s: %s[%d] of %s\n",
848 oldstate = fsm_getstate(fi);
861 fsm_newstate(fi, oldstate);
875 static void ctcm_chx_rxiniterr(
fsm_instance *fi,
int event,
void *arg)
886 ctcm_chx_restart(fi, event, arg);
897 "Initialization failed with RX/TX init handshake "
910 static void ctcm_chx_rxinitfail(
fsm_instance *fi,
int event,
void *arg)
917 "%s(%s): RX %s busy, init. fail",
930 static void ctcm_chx_rxdisc(
fsm_instance *fi,
int event,
void *arg)
938 "%s: %s: remote disconnect - re-init ...",
962 static void ctcm_chx_txiniterr(
fsm_instance *fi,
int event,
void *arg)
971 ctcm_chx_restart(fi, event, arg);
982 "Initialization failed with RX/TX init handshake "
994 static void ctcm_chx_txretry(
fsm_instance *fi,
int event,
void *arg)
1005 if (ch->
retry++ > 3) {
1008 "%s: %s: retries exceeded",
1014 ctcm_chx_restart(fi, event, arg);
1019 "%s : %s: retry %d",
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)) {
1029 "%s: %s: IDAL alloc failed",
1032 ctcm_chx_restart(fi, event, arg);
1042 ctcmpc_dumpit((
char *)&ch->
ccw[3],
1043 sizeof(
struct ccw1) * 3);
1046 (
unsigned long)ch, 0xff, 0);
1067 static void ctcm_chx_iofatal(
fsm_instance *fi,
int event,
void *arg)
1076 "%s: %s: %s unrecoverable channel error",
1080 priv->
stats.tx_dropped++;
1081 priv->
stats.tx_errors++;
1217 static void ctcmpc_chx_txdone(
fsm_instance *fi,
int event,
void *arg)
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)
1243 if (ch->
irb->scsw.cmd.count != 0)
1245 "%s(%s): TX not complete, remaining %d bytes",
1249 priv->
stats.tx_packets++;
1252 priv->
stats.tx_bytes += 2;
1259 clear_normalized_cda(&ch->
ccw[4]);
1266 if (ctcm_checkalloc_buffer(ch)) {
1282 " data_space:%04x\n",
1283 __func__, data_space);
1287 p_header = (
struct pdu *)
1298 " to 32 bytes sent to vtam\n", __func__);
1302 data_space -= skb->
len;
1303 priv->
stats.tx_packets++;
1308 if (peekskb->
len > data_space)
1336 "data to vtam from collect_q\n", __func__);
1341 clear_normalized_cda(&ch->
ccw[1]);
1344 (
void *)(
unsigned long)ch->
ccw[1].cda,
1348 if (set_normalized_cda(&ch->
ccw[1], ch->
trans_skb->data)) {
1352 "%s: %s: IDAL alloc failed",
1359 (
void *)(
unsigned long)ch->
ccw[1].cda,
1366 ctcmpc_dumpit((
char *)&ch->
ccw[0],
sizeof(
struct ccw1) * 3);
1368 (
unsigned long)ch, 0xff, 0);
1369 ch->
prof.doios_multi++;
1371 priv->
stats.tx_dropped +=
i;
1372 priv->
stats.tx_errors +=
i;
1377 ctcm_clear_busy(dev);
1389 static void ctcmpc_chx_rx(
fsm_instance *fi,
int event,
void *arg)
1397 unsigned long saveflags = 0;
1400 CTCM_PR_DEBUG(
"%s: %s: cp:%i %s maxbuf : %04x, len: %04x\n",
1407 "%s(%s): TRANS_SKB = NULL",
1414 "%s(%s): packet length %d to short",
1416 priv->
stats.rx_dropped++;
1417 priv->
stats.rx_length_errors++;
1424 if (new_skb ==
NULL) {
1426 "%s(%d): skb allocation failed",
1431 switch (fsm_getstate(grp->
fsm)) {
1439 skb->
data, block_len);
1452 switch (fsm_getstate(grp->
fsm)) {
1456 if (ctcm_checkalloc_buffer(ch))
1463 ctcmpc_dumpit((
char *)&ch->
ccw[0],
1464 sizeof(
struct ccw1) * 3);
1470 (
unsigned long)ch, 0xff, 0);
1472 spin_unlock_irqrestore(
1481 __func__, dev->
name, ch, ch->
id);
1492 static void ctcmpc_chx_firstio(
fsm_instance *fi,
int event,
void *arg)
1500 __func__, ch->
id, ch);
1503 "%s: %s: chstate:%i, grpstate:%i, prot:%i\n",
1511 if (ctcm_checkalloc_buffer(ch))
1514 switch (fsm_getstate(fi)) {
1533 __func__, ch->
id, ch);
1553 unsigned long saveflags = 0;
1556 CTCM_PR_DEBUG(
"%s: %s: %s: cp:%i, chstate:%i grpstate:%i\n",
1558 fsm_getstate(fi), fsm_getstate(grp->
fsm));
1563 switch (fsm_getstate(grp->
fsm)) {
1566 if (ctcm_checkalloc_buffer(ch))
1577 (
unsigned long)ch, 0xff, 0);
1579 spin_unlock_irqrestore(
1608 CTCM_PR_DEBUG(
"%s(%s): %s(ch=0x%p), cp=%i, ChStat:%s, GrpStat:%s\n",
1612 switch (fsm_getstate(grp->
fsm)) {
1640 switch (fsm_getstate(ch->
fsm)) {
1660 static void ctcmpc_chx_attnbusy(
fsm_instance *fsm,
int event,
void *arg)
1668 __func__, dev->
name, ch->
id,
1673 switch (fsm_getstate(grp->
fsm)) {
1733 "%s(%s): channel %s not added to group",
1745 static void ctcmpc_chx_resend(
fsm_instance *fsm,
int event,
void *arg)
1761 static void ctcmpc_chx_send_sweep(
fsm_instance *fsm,
int event,
void *arg)
1772 unsigned long saveflags = 0;
1796 if (set_normalized_cda(&wch->
ccw[4], skb->
data)) {
1798 ctcm_clear_busy_do(dev);
1808 wch->
ccw[4].count = skb->
len;
1811 switch (header->
th.th_ch_flag) {
1832 (
unsigned long) wch, 0xff, 0);
1840 ctcm_clear_busy_do(dev);
2072 static void dev_action_start(
fsm_instance *fi,
int event,
void *arg)
2083 priv->
mpcg->channels_terminating = 0;
2097 static void dev_action_stop(
fsm_instance *fi,
int event,
void *arg)
2117 static void dev_action_restart(
fsm_instance *fi,
int event,
void *arg)
2132 dev_action_stop(fi, event, arg);
2152 static void dev_action_chup(
fsm_instance *fi,
int event,
void *arg)
2156 int dev_stat = fsm_getstate(fi);
2162 switch (fsm_getstate(fi)) {
2173 "Connected with remote side\n");
2174 ctcm_clear_busy(dev);
2181 "Connected with remote side\n");
2182 ctcm_clear_busy(dev);
2213 static void dev_action_chdown(
fsm_instance *fi,
int event,
void *arg)
2221 switch (fsm_getstate(fi)) {