20 #define KMSG_COMPONENT "ctcm"
21 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
23 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 #include <linux/errno.h>
28 #include <linux/types.h>
31 #include <linux/sched.h>
33 #include <linux/signal.h>
34 #include <linux/string.h>
38 #include <linux/if_arp.h>
39 #include <linux/tcp.h>
41 #include <linux/ctype.h>
42 #include <linux/netdevice.h>
48 #include <linux/bitops.h>
50 #include <linux/wait.h>
58 static const struct xid2 init_xid = {
86 .th_seq_num = 0x00000000,
94 .th_seq_num = 0x00000000,
106 static void ctcmpc_unpack_skb(
struct channel *ch,
struct sk_buff *pskb);
112 static void mpc_action_go_ready(
fsm_instance *fsm,
int event,
void *arg);
113 static void mpc_action_go_inop(
fsm_instance *fi,
int event,
void *arg);
114 static void mpc_action_timeout(
fsm_instance *fi,
int event,
void *arg);
115 static int mpc_validate_xid(
struct mpcg_info *mpcginfo);
116 static void mpc_action_yside_xid(
fsm_instance *fsm,
int event,
void *arg);
117 static void mpc_action_doxid0(
fsm_instance *fsm,
int event,
void *arg);
118 static void mpc_action_doxid7(
fsm_instance *fsm,
int event,
void *arg);
119 static void mpc_action_xside_xid(
fsm_instance *fsm,
int event,
void *arg);
120 static void mpc_action_rcvd_xid0(
fsm_instance *fsm,
int event,
void *arg);
121 static void mpc_action_rcvd_xid7(
fsm_instance *fsm,
int event,
void *arg);
128 void ctcmpc_dumpit(
char *
buf,
int len)
132 char tbuf[82], tdup[82];
139 char bhex[82], duphex[82];
148 for (ct = 0; ct < len; ct++, ptr++, rptr++) {
160 if ((sw == 4) || (sw == 12))
173 if ((0 !=
isprint(*ptr)) && (*ptr >= 0x20))
183 if ((
strcmp(duphex, bhex)) != 0) {
186 "Duplicate as above to %s", addr);
191 addr, boff, bhex, basc);
202 for ( ; rm > 0; rm--, sw++) {
203 if ((sw == 4) || (sw == 12))
211 sprintf(tdup,
"Duplicate as above to %s", addr);
215 addr, boff, bhex, basc);
218 sprintf(tdup,
"Duplicate as above to %s", addr);
223 addr, boff, bhex, basc);
272 pheader = (
struct pdu *)p;
293 for (i = 0; i <
bl; i++)
311 "%s: Device not found by name: %s",
318 "%s(%s): dev->ml_priv is NULL",
324 "%s(%s): priv->mpcg is NULL",
344 dev = ctcmpc_get_dev(port_num);
358 switch (fsm_getstate(grp->
fsm)) {
415 dev = ctcmpc_get_dev(port_num);
430 switch (fsm_getstate(grp->
fsm)) {
455 "%s(%s): REJECTED - inactive channels",
470 "%s(%s): ABORT - PASSIVE XID",
487 "%s(%s): RX-%s not ready for ACTIVE XID0",
501 "%s(%s): WX-%s not ready for ACTIVE XID0",
533 dev = ctcmpc_get_dev(port_num);
540 "%s: %s: refcount = %d\n",
569 dev = ctcmpc_get_dev(port_num);
576 "%s: %s: flowc = %d",
581 mpcg_state = fsm_getstate(grp->
fsm);
612 static int mpc_send_qllc_discontact(
struct net_device *);
617 static void mpc_rcvd_sweep_resp(
struct mpcg_info *mpcginfo)
636 ctcm_clear_busy_do(dev);
649 static void ctcmpc_send_sweep_resp(
struct channel *rch)
661 if (sweep_skb ==
NULL) {
663 "%s(%s): sweep_skb allocation ERROR\n",
675 header->
th.th_seg = 0x00 ;
677 header->
th.th_blk_flag = 0x00;
678 header->
th.th_is_xid = 0x00;
679 header->
th.th_seq_num = 0x00;
695 ctcm_clear_busy_do(dev);
704 static void mpc_rcvd_sweep_req(
struct mpcg_info *mpcginfo)
714 " %s(): ch=0x%p id=%s\n", __func__, ch, ch->
id);
718 ctcm_test_and_set_busy(dev);
726 ctcmpc_send_sweep_resp(ch);
734 static const char *mpcg_event_names[] = {
745 static const char *mpcg_state_names[] = {
765 static const fsm_node mpcg_fsm[] = {
833 static int mpcg_fsm_len =
ARRAY_SIZE(mpcg_fsm);
839 static void mpc_action_go_ready(
fsm_instance *fsm,
int event,
void *arg)
847 "%s(%s): No MPC group",
855 priv->
xid->xid2_flag2 = 0x00;
892 "%s(%s): No MPC group",
898 "%s: %s: GROUP TRANSITIONED TO READY, maxbuf = %d\n",
919 ctcm_clear_busy(dev);
947 "%s(%s): No MPC group",
955 "%s: %i / Grp:%s total_channels=%i, active_channels: "
956 "read=%i, write=%i\n", __func__, action,
974 "%s(%s): Couldn't alloc ch xid_skb\n",
986 skb_reset_tail_pointer(ch->
xid_skb);
993 ch->
xid->xid2_dlc_type =
998 ch->
xid->xid2_buf_len = 0x00;
1001 skb_reset_tail_pointer(ch->
xid_skb);
1011 "%s: %s: MPC GROUP CHANNELS ACTIVE\n",
1012 __func__, dev->
name);
1035 "exit %s: %i / Grp:%s total_channels=%i, active_channels: "
1036 "read=%i, write=%i\n", __func__, action,
1052 static void ctcmpc_unpack_skb(
struct channel *ch,
struct sk_buff *pskb)
1057 struct pdu *curr_pdu;
1061 int pdu_last_seen = 0;
1101 "got:%08x\n", __func__,
1114 while ((pskb->
len > 0) && !pdu_last_seen) {
1115 curr_pdu = (
struct pdu *)pskb->
data;
1120 __func__, pskb->
len);
1133 "%s(%s): Dropping packet with "
1137 priv->
stats.rx_dropped++;
1138 priv->
stats.rx_length_errors++;
1141 skb_reset_mac_header(pskb);
1145 if ((new_len == 0) || (new_len > pskb->
len)) {
1149 "%s(%s): non valid pdu_offset: %04x",
1154 skb = __dev_alloc_skb(new_len+4,
GFP_ATOMIC);
1158 "%s(%s): MEMORY allocation error",
1160 priv->
stats.rx_dropped++;
1166 skb_reset_mac_header(skb);
1177 "skb len: %d \n", __func__,
1178 (
unsigned long)skb, skb->
len);
1180 "of pdu_data sent\n", __func__);
1181 ctcmpc_dump32((
char *)skb->
data, skb->
len);
1186 priv->
stats.rx_packets++;
1187 priv->
stats.rx_bytes += skblen;
1192 if (mpcginfo ==
NULL)
1196 mpcginfo->
th = header;
1197 mpcginfo->
skb = pskb;
1202 mpcginfo->
sweep = sweep;
1204 mpc_rcvd_sweep_req(mpcginfo);
1206 mpc_rcvd_sweep_resp(mpcginfo);
1210 mpcginfo->
xid = thisxid;
1216 "%s(%s): control pkt expected\n",
1218 priv->
stats.rx_dropped++;
1222 ctcmpc_dump_skb(pskb, -8);
1230 "The network backlog for %s is exceeded, "
1231 "package dropped\n", __func__);
1236 __func__, dev->
name, ch, ch->
id);
1260 ctcmpc_unpack_skb(ch, skb);
1269 if (skb == skb_peek(&ch->
io_queue))
1273 __func__, dev->
name, ch, ch->
id);
1291 grp->
fsm =
init_fsm(
"mpcg", mpcg_state_names, mpcg_event_names,
1317 grp->
xid->xid2_adj_id =
jiffies | 0xfff00000;
1353 static void mpc_action_nop(
fsm_instance *fi,
int event,
void *arg)
1363 static void mpc_action_go_inop(
fsm_instance *fi,
int event,
void *arg)
1385 "%s(%s): MPC GROUP INOPERATIVE",
1431 mpc_send_qllc_discontact(dev);
1446 "%s(%s): MPC GROUP RECOVERY SCHEDULED",
1453 "%s(%s): NO MPC GROUP RECOVERY ATTEMPTED",
1467 static void mpc_action_timeout(
fsm_instance *fi,
int event,
void *arg)
1482 switch (fsm_getstate(grp->
fsm)) {
1539 unsigned long saveflags = 0;
1543 (
unsigned long)ch, 0xff, 0);
1559 static int mpc_validate_xid(
struct mpcg_info *mpcginfo)
1577 "%s(%s): xid = NULL",
1590 "%s(%s): r/w channel pairing mismatch",
1616 our_id = (
__u64)priv->
xid->xid2_adj_id;
1617 our_id = our_id << 32;
1618 our_id = our_id + priv->
xid->xid2_sender_id;
1620 their_id = their_id << 32;
1623 if (our_id < their_id) {
1626 "%s(%s): WE HAVE LOW ID - TAKE XSIDE",
1631 "%s(%s): WE HAVE HIGH ID - TAKE YSIDE",
1640 "%s(%s): xid flag byte4 mismatch",
1647 "%s(%s): xid NOGOOD",
1654 "%s(%s): Adjacent Station ID Mismatch",
1661 "%s(%s): Sender Address Mismatch",
1668 "The XID used in the MPC protocol is not valid, "
1670 priv->
xid->xid2_flag2 = 0x40;
1686 unsigned long saveflags = 0;
1692 if (ctcm_checkalloc_buffer(ch))
1727 ch->
ccw[8].count = 0;
1728 ch->
ccw[8].cda = 0x00;
1732 "%s(%s): xid_th=%p, xid=%p, xid_id=%p",
1735 if (side ==
XSIDE) {
1796 ch->
ccw[13].count = 4;
1800 ch->
ccw[14].count = 0;
1801 ch->
ccw[14].cda = 0;
1818 (
unsigned long)ch, 0xff, 0);
1825 (side ==
XSIDE) ?
"x-side XID" :
"y-side XID");
1830 __func__, ch, ch->
id);
1839 static void mpc_action_xside_xid(
fsm_instance *fsm,
int event,
void *arg)
1841 mpc_action_side_xid(fsm, arg,
XSIDE);
1848 static void mpc_action_yside_xid(
fsm_instance *fsm,
int event,
void *arg)
1850 mpc_action_side_xid(fsm, arg,
YSIDE);
1857 static void mpc_action_doxid0(
fsm_instance *fsm,
int event,
void *arg)
1869 "%s(%s): ch->xid == NULL",
1878 switch (fsm_getstate(grp->
fsm)) {
1898 static void mpc_action_doxid7(
fsm_instance *fsm,
int event,
void *arg)
1913 struct xid2 *thisxid = ch->
xid;
1915 skb_reset_tail_pointer(ch->
xid_skb);
1970 static void mpc_action_rcvd_xid0(
fsm_instance *fsm,
int event,
void *arg)
1992 switch (fsm_getstate(grp->
fsm)) {
1995 mpc_validate_xid(mpcginfo);
1999 mpc_validate_xid(mpcginfo);
2004 mpc_validate_xid(mpcginfo);
2011 mpc_validate_xid(mpcginfo);
2018 CTCM_PR_DEBUG(
"ctcmpc:%s() %s xid2:%i xid7:%i xidt_p2:%i \n",
2021 CTCM_PR_DEBUG(
"ctcmpc:%s() %s grpstate: %s chanstate: %s \n",
2033 static void mpc_action_rcvd_xid7(
fsm_instance *fsm,
int event,
void *arg)
2043 CTCM_PR_DEBUG(
"%s: outstanding_xid7: %i, outstanding_xid7_p2: %i\n",
2048 skb_reset_tail_pointer(ch->
xid_skb);
2051 switch (fsm_getstate(grp->
fsm)) {
2054 mpc_validate_xid(mpcginfo);
2058 mpc_validate_xid(mpcginfo);
2070 mpc_validate_xid(mpcginfo);
2074 mpc_validate_xid(mpcginfo);
2085 static int mpc_send_qllc_discontact(
struct net_device *dev)
2089 struct qllc *qllcptr;
2117 new_len =
sizeof(
struct qllc);
2118 qllcptr = kzalloc(new_len, gfp_type() |
GFP_DMA);
2119 if (qllcptr ==
NULL) {
2121 "%s(%s): qllcptr allocation error",
2133 "%s(%s): skb allocation error",
2135 priv->
stats.rx_dropped++;
2143 if (skb_headroom(skb) < 4) {
2145 "%s(%s): skb_headroom error",
2160 skb_reset_mac_header(skb);