1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2004, 2007
10 This module exports functions to be used by CCS:
11 EXPORT_SYMBOL(ctc_mpc_alloc_channel);
12 EXPORT_SYMBOL(ctc_mpc_establish_connectivity);
13 EXPORT_SYMBOL(ctc_mpc_dealloc_ch);
14 EXPORT_SYMBOL(ctc_mpc_flow_control);
21 #define KMSG_COMPONENT "ctcm"
22 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/errno.h>
29 #include <linux/types.h>
30 #include <linux/interrupt.h>
31 #include <linux/timer.h>
32 #include <linux/sched.h>
34 #include <linux/signal.h>
35 #include <linux/string.h>
36 #include <linux/proc_fs.h>
39 #include <linux/if_arp.h>
40 #include <linux/tcp.h>
41 #include <linux/skbuff.h>
42 #include <linux/ctype.h>
43 #include <linux/netdevice.h>
46 #include <linux/io.h> /* instead of <asm/io.h> ok ? */
47 #include <asm/ccwdev.h>
48 #include <asm/ccwgroup.h>
49 #include <linux/bitops.h> /* instead of <asm/bitops.h> ok ? */
50 #include <linux/uaccess.h> /* instead of <asm/uaccess.h> ok ? */
51 #include <linux/wait.h>
52 #include <linux/moduleparam.h>
53 #include <asm/idals.h>
55 #include "ctcm_main.h"
57 #include "ctcm_fsms.h"
59 static const struct xid2 init_xid = {
60 .xid2_type_id = XID_FM2,
72 .xid2_option = XID2_0,
75 .xid2_dlc_type = XID2_READ_SIDE,
79 .xid2_buf_len = (MPC_BUFSIZE_DEFAULT - 35),
82 static const struct th_header thnorm = {
84 .th_ch_flag = TH_IS_XID,
85 .th_blk_flag = TH_DATA_IS_XID,
87 .th_seq_num = 0x00000000,
90 static const struct th_header thdummy = {
93 .th_blk_flag = TH_DATA_IS_XID,
95 .th_seq_num = 0x00000000,
99 * Definition of one MPC group
103 * Compatibility macros for busy handling
104 * of network devices.
107 static void ctcmpc_unpack_skb(struct channel *ch, struct sk_buff *pskb);
110 * MPC Group state machine actions (static prototypes)
112 static void mpc_action_nop(fsm_instance *fsm, int event, void *arg);
113 static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg);
114 static void mpc_action_go_inop(fsm_instance *fi, int event, void *arg);
115 static void mpc_action_timeout(fsm_instance *fi, int event, void *arg);
116 static int mpc_validate_xid(struct mpcg_info *mpcginfo);
117 static void mpc_action_yside_xid(fsm_instance *fsm, int event, void *arg);
118 static void mpc_action_doxid0(fsm_instance *fsm, int event, void *arg);
119 static void mpc_action_doxid7(fsm_instance *fsm, int event, void *arg);
120 static void mpc_action_xside_xid(fsm_instance *fsm, int event, void *arg);
121 static void mpc_action_rcvd_xid0(fsm_instance *fsm, int event, void *arg);
122 static void mpc_action_rcvd_xid7(fsm_instance *fsm, int event, void *arg);
125 /*-------------------------------------------------------------------*
126 * Dump buffer format *
128 *--------------------------------------------------------------------*/
129 void ctcmpc_dumpit(char *buf, int len)
131 __u32 ct, sw, rm, dup;
133 char tbuf[82], tdup[82];
136 char bhex[82], duphex[82];
145 for (ct = 0; ct < len; ct++, ptr++, rptr++) {
147 sprintf(addr, "%16.16llx", (__u64)rptr);
149 sprintf(boff, "%4.4X", (__u32)ct);
153 if ((sw == 4) || (sw == 12))
158 sprintf(tbuf, "%2.2llX", (__u64)*ptr);
162 if ((0 != isprint(*ptr)) && (*ptr >= 0x20))
172 if ((strcmp(duphex, bhex)) != 0) {
175 "Duplicate as above to %s", addr);
176 ctcm_pr_debug(" --- %s ---\n",
179 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
180 addr, boff, bhex, basc);
182 strcpy(duphex, bhex);
191 for ( ; rm > 0; rm--, sw++) {
192 if ((sw == 4) || (sw == 12))
200 sprintf(tdup, "Duplicate as above to %s", addr);
201 ctcm_pr_debug(" --- %s ---\n", tdup);
203 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
204 addr, boff, bhex, basc);
207 sprintf(tdup, "Duplicate as above to %s", addr);
208 ctcm_pr_debug(" --- %s ---\n", tdup);
211 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
212 addr, boff, bhex, basc);
218 } /* end of ctcmpc_dumpit */
223 * Dump header and first 16 bytes of an sk_buff for debugging purposes.
225 * skb The sk_buff to dump.
226 * offset Offset relative to skb-data, where to start the dump.
228 void ctcmpc_dump_skb(struct sk_buff *skb, int offset)
231 struct th_header *header;
240 header = (struct th_header *)p;
242 ctcm_pr_debug("dump:\n");
243 ctcm_pr_debug("skb len=%d \n", skb->len);
245 switch (header->th_ch_flag) {
250 if ((header->th_blk_flag == TH_DATA_IS_XID) &&
251 (header->th_is_xid == 0x01))
261 pheader = (struct pdu *)p;
262 ctcm_pr_debug("pdu->offset: %d hex: %04x\n",
263 pheader->pdu_offset, pheader->pdu_offset);
264 ctcm_pr_debug("pdu->flag : %02x\n", pheader->pdu_flag);
265 ctcm_pr_debug("pdu->proto : %02x\n", pheader->pdu_proto);
266 ctcm_pr_debug("pdu->seq : %02x\n", pheader->pdu_seq);
270 ctcm_pr_debug("th->seg : %02x\n", header->th_seg);
271 ctcm_pr_debug("th->ch : %02x\n", header->th_ch_flag);
272 ctcm_pr_debug("th->blk_flag: %02x\n", header->th_blk_flag);
273 ctcm_pr_debug("th->type : %s\n",
274 (header->th_is_xid) ? "DATA" : "XID");
275 ctcm_pr_debug("th->seqnum : %04x\n", header->th_seq_num);
281 ctcm_pr_debug("data: ");
282 for (i = 0; i < bl; i++)
283 ctcm_pr_debug("%02x%s", *p++, (i % 16) ? " " : "\n");
288 static struct net_device *ctcmpc_get_dev(int port_num)
291 struct net_device *dev;
292 struct ctcm_priv *priv;
294 sprintf(device, "%s%i", MPC_DEVICE_NAME, port_num);
296 dev = __dev_get_by_name(&init_net, device);
299 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
300 "%s: Device not found by name: %s",
301 CTCM_FUNTAIL, device);
306 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
307 "%s(%s): dev->ml_priv is NULL",
308 CTCM_FUNTAIL, device);
311 if (priv->mpcg == NULL) {
312 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
313 "%s(%s): priv->mpcg is NULL",
314 CTCM_FUNTAIL, device);
321 * ctc_mpc_alloc_channel
322 * (exported interface)
324 * Device Initialization :
325 * ACTPATH driven IO operations
327 int ctc_mpc_alloc_channel(int port_num, void (*callback)(int, int))
329 struct net_device *dev;
330 struct mpc_group *grp;
331 struct ctcm_priv *priv;
333 dev = ctcmpc_get_dev(port_num);
339 grp->allochanfunc = callback;
340 grp->port_num = port_num;
341 grp->port_persist = 1;
343 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
345 CTCM_FUNTAIL, dev->name, fsm_getstate_str(grp->fsm));
347 switch (fsm_getstate(grp->fsm)) {
348 case MPCG_STATE_INOP:
349 /* Group is in the process of terminating */
350 grp->alloc_called = 1;
352 case MPCG_STATE_RESET:
353 /* MPC Group will transition to state */
354 /* MPCG_STATE_XID2INITW iff the minimum number */
355 /* of 1 read and 1 write channel have successfully*/
357 /*fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);*/
359 grp->send_qllc_disc = 1;
361 case MPCG_STATE_XID0IOWAIT:
362 fsm_deltimer(&grp->timer);
363 grp->outstanding_xid2 = 0;
364 grp->outstanding_xid7 = 0;
365 grp->outstanding_xid7_p2 = 0;
366 grp->saved_xid2 = NULL;
369 fsm_event(priv->fsm, DEV_EVENT_START, dev);
371 case MPCG_STATE_READY:
372 /* XID exchanges completed after PORT was activated */
373 /* Link station already active */
374 /* Maybe timing issue...retry callback */
375 grp->allocchan_callback_retries++;
376 if (grp->allocchan_callback_retries < 4) {
377 if (grp->allochanfunc)
378 grp->allochanfunc(grp->port_num,
379 grp->group_max_buflen);
381 /* there are problems...bail out */
382 /* there may be a state mismatch so restart */
383 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
384 grp->allocchan_callback_retries = 0;
391 EXPORT_SYMBOL(ctc_mpc_alloc_channel);
394 * ctc_mpc_establish_connectivity
395 * (exported interface)
397 void ctc_mpc_establish_connectivity(int port_num,
398 void (*callback)(int, int, int))
400 struct net_device *dev;
401 struct mpc_group *grp;
402 struct ctcm_priv *priv;
403 struct channel *rch, *wch;
405 dev = ctcmpc_get_dev(port_num);
410 rch = priv->channel[CTCM_READ];
411 wch = priv->channel[CTCM_WRITE];
413 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
415 CTCM_FUNTAIL, dev->name, fsm_getstate_str(grp->fsm));
417 grp->estconnfunc = callback;
418 grp->port_num = port_num;
420 switch (fsm_getstate(grp->fsm)) {
421 case MPCG_STATE_READY:
422 /* XID exchanges completed after PORT was activated */
423 /* Link station already active */
424 /* Maybe timing issue...retry callback */
425 fsm_deltimer(&grp->timer);
426 grp->estconn_callback_retries++;
427 if (grp->estconn_callback_retries < 4) {
428 if (grp->estconnfunc) {
429 grp->estconnfunc(grp->port_num, 0,
430 grp->group_max_buflen);
431 grp->estconnfunc = NULL;
434 /* there are problems...bail out */
435 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
436 grp->estconn_callback_retries = 0;
439 case MPCG_STATE_INOP:
440 case MPCG_STATE_RESET:
441 /* MPC Group is not ready to start XID - min num of */
442 /* 1 read and 1 write channel have not been acquired*/
444 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
445 "%s(%s): REJECTED - inactive channels",
446 CTCM_FUNTAIL, dev->name);
447 if (grp->estconnfunc) {
448 grp->estconnfunc(grp->port_num, -1, 0);
449 grp->estconnfunc = NULL;
452 case MPCG_STATE_XID2INITW:
453 /* alloc channel was called but no XID exchange */
454 /* has occurred. initiate xside XID exchange */
455 /* make sure yside XID0 processing has not started */
457 if ((fsm_getstate(rch->fsm) > CH_XID0_PENDING) ||
458 (fsm_getstate(wch->fsm) > CH_XID0_PENDING)) {
459 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
460 "%s(%s): ABORT - PASSIVE XID",
461 CTCM_FUNTAIL, dev->name);
464 grp->send_qllc_disc = 1;
465 fsm_newstate(grp->fsm, MPCG_STATE_XID0IOWAIT);
466 fsm_deltimer(&grp->timer);
467 fsm_addtimer(&grp->timer, MPC_XID_TIMEOUT_VALUE,
468 MPCG_EVENT_TIMER, dev);
469 grp->outstanding_xid7 = 0;
470 grp->outstanding_xid7_p2 = 0;
471 grp->saved_xid2 = NULL;
472 if ((rch->in_mpcgroup) &&
473 (fsm_getstate(rch->fsm) == CH_XID0_PENDING))
474 fsm_event(grp->fsm, MPCG_EVENT_XID0DO, rch);
476 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
477 "%s(%s): RX-%s not ready for ACTIVE XID0",
478 CTCM_FUNTAIL, dev->name, rch->id);
479 if (grp->estconnfunc) {
480 grp->estconnfunc(grp->port_num, -1, 0);
481 grp->estconnfunc = NULL;
483 fsm_deltimer(&grp->timer);
486 if ((wch->in_mpcgroup) &&
487 (fsm_getstate(wch->fsm) == CH_XID0_PENDING))
488 fsm_event(grp->fsm, MPCG_EVENT_XID0DO, wch);
490 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
491 "%s(%s): WX-%s not ready for ACTIVE XID0",
492 CTCM_FUNTAIL, dev->name, wch->id);
493 if (grp->estconnfunc) {
494 grp->estconnfunc(grp->port_num, -1, 0);
495 grp->estconnfunc = NULL;
497 fsm_deltimer(&grp->timer);
501 case MPCG_STATE_XID0IOWAIT:
502 /* already in active XID negotiations */
508 CTCM_PR_DEBUG("Exit %s()\n", __func__);
511 EXPORT_SYMBOL(ctc_mpc_establish_connectivity);
515 * (exported interface)
517 void ctc_mpc_dealloc_ch(int port_num)
519 struct net_device *dev;
520 struct ctcm_priv *priv;
521 struct mpc_group *grp;
523 dev = ctcmpc_get_dev(port_num);
529 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_DEBUG,
530 "%s: %s: refcount = %d\n",
531 CTCM_FUNTAIL, dev->name, netdev_refcnt_read(dev));
533 fsm_deltimer(&priv->restart_timer);
534 grp->channels_terminating = 0;
535 fsm_deltimer(&grp->timer);
536 grp->allochanfunc = NULL;
537 grp->estconnfunc = NULL;
538 grp->port_persist = 0;
539 grp->send_qllc_disc = 0;
540 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
545 EXPORT_SYMBOL(ctc_mpc_dealloc_ch);
548 * ctc_mpc_flow_control
549 * (exported interface)
551 void ctc_mpc_flow_control(int port_num, int flowc)
553 struct ctcm_priv *priv;
554 struct mpc_group *grp;
555 struct net_device *dev;
559 dev = ctcmpc_get_dev(port_num);
565 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
566 "%s: %s: flowc = %d",
567 CTCM_FUNTAIL, dev->name, flowc);
569 rch = priv->channel[CTCM_READ];
571 mpcg_state = fsm_getstate(grp->fsm);
574 if (mpcg_state == MPCG_STATE_FLOWC)
576 if (mpcg_state == MPCG_STATE_READY) {
577 if (grp->flow_off_called == 1)
578 grp->flow_off_called = 0;
580 fsm_newstate(grp->fsm, MPCG_STATE_FLOWC);
585 if (mpcg_state == MPCG_STATE_FLOWC) {
586 fsm_newstate(grp->fsm, MPCG_STATE_READY);
587 /* ensure any data that has accumulated */
588 /* on the io_queue will now be sen t */
589 tasklet_schedule(&rch->ch_tasklet);
591 /* possible race condition */
592 if (mpcg_state == MPCG_STATE_READY) {
593 grp->flow_off_called = 1;
600 EXPORT_SYMBOL(ctc_mpc_flow_control);
602 static int mpc_send_qllc_discontact(struct net_device *);
605 * helper function of ctcmpc_unpack_skb
607 static void mpc_rcvd_sweep_resp(struct mpcg_info *mpcginfo)
609 struct channel *rch = mpcginfo->ch;
610 struct net_device *dev = rch->netdev;
611 struct ctcm_priv *priv = dev->ml_priv;
612 struct mpc_group *grp = priv->mpcg;
613 struct channel *ch = priv->channel[CTCM_WRITE];
615 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, ch, ch->id);
616 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
618 grp->sweep_rsp_pend_num--;
620 if ((grp->sweep_req_pend_num == 0) &&
621 (grp->sweep_rsp_pend_num == 0)) {
622 fsm_deltimer(&ch->sweep_timer);
624 rch->th_seq_num = 0x00;
625 ch->th_seq_num = 0x00;
626 ctcm_clear_busy_do(dev);
636 * helper function of mpc_rcvd_sweep_req
637 * which is a helper of ctcmpc_unpack_skb
639 static void ctcmpc_send_sweep_resp(struct channel *rch)
641 struct net_device *dev = rch->netdev;
642 struct ctcm_priv *priv = dev->ml_priv;
643 struct mpc_group *grp = priv->mpcg;
644 struct th_sweep *header;
645 struct sk_buff *sweep_skb;
646 struct channel *ch = priv->channel[CTCM_WRITE];
648 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, rch, rch->id);
650 sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC | GFP_DMA);
651 if (sweep_skb == NULL) {
652 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
653 "%s(%s): sweep_skb allocation ERROR\n",
654 CTCM_FUNTAIL, rch->id);
658 header = skb_put_zero(sweep_skb, TH_SWEEP_LENGTH);
659 header->th.th_ch_flag = TH_SWEEP_RESP;
660 header->sw.th_last_seq = ch->th_seq_num;
662 netif_trans_update(dev);
663 skb_queue_tail(&ch->sweep_queue, sweep_skb);
665 fsm_addtimer(&ch->sweep_timer, 100, CTC_EVENT_RSWEEP_TIMER, ch);
671 ctcm_clear_busy_do(dev);
672 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
678 * helper function of ctcmpc_unpack_skb
680 static void mpc_rcvd_sweep_req(struct mpcg_info *mpcginfo)
682 struct channel *rch = mpcginfo->ch;
683 struct net_device *dev = rch->netdev;
684 struct ctcm_priv *priv = dev->ml_priv;
685 struct mpc_group *grp = priv->mpcg;
686 struct channel *ch = priv->channel[CTCM_WRITE];
689 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
690 " %s(): ch=0x%p id=%s\n", __func__, ch, ch->id);
692 if (grp->in_sweep == 0) {
694 ctcm_test_and_set_busy(dev);
695 grp->sweep_req_pend_num = grp->active_channels[CTCM_READ];
696 grp->sweep_rsp_pend_num = grp->active_channels[CTCM_READ];
699 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
701 grp->sweep_req_pend_num--;
702 ctcmpc_send_sweep_resp(ch);
708 * MPC Group Station FSM definitions
710 static const char *mpcg_event_names[] = {
711 [MPCG_EVENT_INOP] = "INOP Condition",
712 [MPCG_EVENT_DISCONC] = "Discontact Received",
713 [MPCG_EVENT_XID0DO] = "Channel Active - Start XID",
714 [MPCG_EVENT_XID2] = "XID2 Received",
715 [MPCG_EVENT_XID2DONE] = "XID0 Complete",
716 [MPCG_EVENT_XID7DONE] = "XID7 Complete",
717 [MPCG_EVENT_TIMER] = "XID Setup Timer",
718 [MPCG_EVENT_DOIO] = "XID DoIO",
721 static const char *mpcg_state_names[] = {
722 [MPCG_STATE_RESET] = "Reset",
723 [MPCG_STATE_INOP] = "INOP",
724 [MPCG_STATE_XID2INITW] = "Passive XID- XID0 Pending Start",
725 [MPCG_STATE_XID2INITX] = "Passive XID- XID0 Pending Complete",
726 [MPCG_STATE_XID7INITW] = "Passive XID- XID7 Pending P1 Start",
727 [MPCG_STATE_XID7INITX] = "Passive XID- XID7 Pending P2 Complete",
728 [MPCG_STATE_XID0IOWAIT] = "Active XID- XID0 Pending Start",
729 [MPCG_STATE_XID0IOWAIX] = "Active XID- XID0 Pending Complete",
730 [MPCG_STATE_XID7INITI] = "Active XID- XID7 Pending Start",
731 [MPCG_STATE_XID7INITZ] = "Active XID- XID7 Pending Complete ",
732 [MPCG_STATE_XID7INITF] = "XID - XID7 Complete ",
733 [MPCG_STATE_FLOWC] = "FLOW CONTROL ON",
734 [MPCG_STATE_READY] = "READY",
738 * The MPC Group Station FSM
741 static const fsm_node mpcg_fsm[] = {
742 { MPCG_STATE_RESET, MPCG_EVENT_INOP, mpc_action_go_inop },
743 { MPCG_STATE_INOP, MPCG_EVENT_INOP, mpc_action_nop },
744 { MPCG_STATE_FLOWC, MPCG_EVENT_INOP, mpc_action_go_inop },
746 { MPCG_STATE_READY, MPCG_EVENT_DISCONC, mpc_action_discontact },
747 { MPCG_STATE_READY, MPCG_EVENT_INOP, mpc_action_go_inop },
749 { MPCG_STATE_XID2INITW, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
750 { MPCG_STATE_XID2INITW, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
751 { MPCG_STATE_XID2INITW, MPCG_EVENT_INOP, mpc_action_go_inop },
752 { MPCG_STATE_XID2INITW, MPCG_EVENT_TIMER, mpc_action_timeout },
753 { MPCG_STATE_XID2INITW, MPCG_EVENT_DOIO, mpc_action_yside_xid },
755 { MPCG_STATE_XID2INITX, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
756 { MPCG_STATE_XID2INITX, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
757 { MPCG_STATE_XID2INITX, MPCG_EVENT_INOP, mpc_action_go_inop },
758 { MPCG_STATE_XID2INITX, MPCG_EVENT_TIMER, mpc_action_timeout },
759 { MPCG_STATE_XID2INITX, MPCG_EVENT_DOIO, mpc_action_yside_xid },
761 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID2DONE, mpc_action_doxid7 },
762 { MPCG_STATE_XID7INITW, MPCG_EVENT_DISCONC, mpc_action_discontact },
763 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
764 { MPCG_STATE_XID7INITW, MPCG_EVENT_INOP, mpc_action_go_inop },
765 { MPCG_STATE_XID7INITW, MPCG_EVENT_TIMER, mpc_action_timeout },
766 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
767 { MPCG_STATE_XID7INITW, MPCG_EVENT_DOIO, mpc_action_yside_xid },
769 { MPCG_STATE_XID7INITX, MPCG_EVENT_DISCONC, mpc_action_discontact },
770 { MPCG_STATE_XID7INITX, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
771 { MPCG_STATE_XID7INITX, MPCG_EVENT_INOP, mpc_action_go_inop },
772 { MPCG_STATE_XID7INITX, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
773 { MPCG_STATE_XID7INITX, MPCG_EVENT_TIMER, mpc_action_timeout },
774 { MPCG_STATE_XID7INITX, MPCG_EVENT_DOIO, mpc_action_yside_xid },
776 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
777 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_DISCONC, mpc_action_discontact },
778 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
779 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_INOP, mpc_action_go_inop },
780 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_TIMER, mpc_action_timeout },
781 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_DOIO, mpc_action_xside_xid },
783 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
784 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_DISCONC, mpc_action_discontact },
785 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
786 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_INOP, mpc_action_go_inop },
787 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_TIMER, mpc_action_timeout },
788 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_DOIO, mpc_action_xside_xid },
790 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID2DONE, mpc_action_doxid7 },
791 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
792 { MPCG_STATE_XID7INITI, MPCG_EVENT_DISCONC, mpc_action_discontact },
793 { MPCG_STATE_XID7INITI, MPCG_EVENT_INOP, mpc_action_go_inop },
794 { MPCG_STATE_XID7INITI, MPCG_EVENT_TIMER, mpc_action_timeout },
795 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
796 { MPCG_STATE_XID7INITI, MPCG_EVENT_DOIO, mpc_action_xside_xid },
798 { MPCG_STATE_XID7INITZ, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
799 { MPCG_STATE_XID7INITZ, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
800 { MPCG_STATE_XID7INITZ, MPCG_EVENT_DISCONC, mpc_action_discontact },
801 { MPCG_STATE_XID7INITZ, MPCG_EVENT_INOP, mpc_action_go_inop },
802 { MPCG_STATE_XID7INITZ, MPCG_EVENT_TIMER, mpc_action_timeout },
803 { MPCG_STATE_XID7INITZ, MPCG_EVENT_DOIO, mpc_action_xside_xid },
805 { MPCG_STATE_XID7INITF, MPCG_EVENT_INOP, mpc_action_go_inop },
806 { MPCG_STATE_XID7INITF, MPCG_EVENT_XID7DONE, mpc_action_go_ready },
809 static int mpcg_fsm_len = ARRAY_SIZE(mpcg_fsm);
812 * MPC Group Station FSM action
813 * CTCM_PROTO_MPC only
815 static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg)
817 struct net_device *dev = arg;
818 struct ctcm_priv *priv = dev->ml_priv;
819 struct mpc_group *grp = priv->mpcg;
822 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
823 "%s(%s): No MPC group",
824 CTCM_FUNTAIL, dev->name);
828 fsm_deltimer(&grp->timer);
830 if (grp->saved_xid2->xid2_flag2 == 0x40) {
831 priv->xid->xid2_flag2 = 0x00;
832 if (grp->estconnfunc) {
833 grp->estconnfunc(grp->port_num, 1,
834 grp->group_max_buflen);
835 grp->estconnfunc = NULL;
836 } else if (grp->allochanfunc)
837 grp->send_qllc_disc = 1;
839 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
840 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
842 CTCM_FUNTAIL, dev->name);
846 grp->port_persist = 1;
847 grp->out_of_sequence = 0;
848 grp->estconn_called = 0;
850 tasklet_hi_schedule(&grp->mpc_tasklet2);
856 * helper of ctcm_init_netdevice
857 * CTCM_PROTO_MPC only
859 void mpc_group_ready(unsigned long adev)
861 struct net_device *dev = (struct net_device *)adev;
862 struct ctcm_priv *priv = dev->ml_priv;
863 struct mpc_group *grp = priv->mpcg;
864 struct channel *ch = NULL;
867 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
868 "%s(%s): No MPC group",
869 CTCM_FUNTAIL, dev->name);
873 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
874 "%s: %s: GROUP TRANSITIONED TO READY, maxbuf = %d\n",
875 CTCM_FUNTAIL, dev->name, grp->group_max_buflen);
877 fsm_newstate(grp->fsm, MPCG_STATE_READY);
879 /* Put up a read on the channel */
880 ch = priv->channel[CTCM_READ];
882 CTCM_PR_DBGDATA("ctcmpc: %s() ToDCM_pdu_seq= %08x\n" ,
883 __func__, ch->pdu_seq);
885 ctcmpc_chx_rxidle(ch->fsm, CTC_EVENT_START, ch);
886 /* Put the write channel in idle state */
887 ch = priv->channel[CTCM_WRITE];
888 if (ch->collect_len > 0) {
889 spin_lock(&ch->collect_lock);
890 ctcm_purge_skb_queue(&ch->collect_queue);
892 spin_unlock(&ch->collect_lock);
894 ctcm_chx_txidle(ch->fsm, CTC_EVENT_START, ch);
895 ctcm_clear_busy(dev);
897 if (grp->estconnfunc) {
898 grp->estconnfunc(grp->port_num, 0,
899 grp->group_max_buflen);
900 grp->estconnfunc = NULL;
901 } else if (grp->allochanfunc)
902 grp->allochanfunc(grp->port_num, grp->group_max_buflen);
904 grp->send_qllc_disc = 1;
905 grp->changed_side = 0;
912 * Increment the MPC Group Active Channel Counts
913 * helper of dev_action (called from channel fsm)
915 void mpc_channel_action(struct channel *ch, int direction, int action)
917 struct net_device *dev = ch->netdev;
918 struct ctcm_priv *priv = dev->ml_priv;
919 struct mpc_group *grp = priv->mpcg;
922 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
923 "%s(%s): No MPC group",
924 CTCM_FUNTAIL, dev->name);
928 CTCM_PR_DEBUG("enter %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
930 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
931 "%s: %i / Grp:%s total_channels=%i, active_channels: "
932 "read=%i, write=%i\n", __func__, action,
933 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
934 grp->active_channels[CTCM_READ],
935 grp->active_channels[CTCM_WRITE]);
937 if ((action == MPC_CHANNEL_ADD) && (ch->in_mpcgroup == 0)) {
938 grp->num_channel_paths++;
939 grp->active_channels[direction]++;
940 grp->outstanding_xid2++;
943 if (ch->xid_skb != NULL)
944 dev_kfree_skb_any(ch->xid_skb);
946 ch->xid_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT,
947 GFP_ATOMIC | GFP_DMA);
948 if (ch->xid_skb == NULL) {
949 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
950 "%s(%s): Couldn't alloc ch xid_skb\n",
951 CTCM_FUNTAIL, dev->name);
952 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
955 ch->xid_skb_data = ch->xid_skb->data;
956 ch->xid_th = (struct th_header *)ch->xid_skb->data;
957 skb_put(ch->xid_skb, TH_HEADER_LENGTH);
958 ch->xid = (struct xid2 *)skb_tail_pointer(ch->xid_skb);
959 skb_put(ch->xid_skb, XID2_LENGTH);
960 ch->xid_id = skb_tail_pointer(ch->xid_skb);
961 ch->xid_skb->data = ch->xid_skb_data;
962 skb_reset_tail_pointer(ch->xid_skb);
963 ch->xid_skb->len = 0;
965 skb_put_data(ch->xid_skb, grp->xid_skb->data,
968 ch->xid->xid2_dlc_type =
969 ((CHANNEL_DIRECTION(ch->flags) == CTCM_READ)
970 ? XID2_READ_SIDE : XID2_WRITE_SIDE);
972 if (CHANNEL_DIRECTION(ch->flags) == CTCM_WRITE)
973 ch->xid->xid2_buf_len = 0x00;
975 ch->xid_skb->data = ch->xid_skb_data;
976 skb_reset_tail_pointer(ch->xid_skb);
977 ch->xid_skb->len = 0;
979 fsm_newstate(ch->fsm, CH_XID0_PENDING);
981 if ((grp->active_channels[CTCM_READ] > 0) &&
982 (grp->active_channels[CTCM_WRITE] > 0) &&
983 (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) {
984 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);
985 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
986 "%s: %s: MPC GROUP CHANNELS ACTIVE\n",
987 __func__, dev->name);
989 } else if ((action == MPC_CHANNEL_REMOVE) &&
990 (ch->in_mpcgroup == 1)) {
992 grp->num_channel_paths--;
993 grp->active_channels[direction]--;
995 if (ch->xid_skb != NULL)
996 dev_kfree_skb_any(ch->xid_skb);
999 if (grp->channels_terminating)
1002 if (((grp->active_channels[CTCM_READ] == 0) &&
1003 (grp->active_channels[CTCM_WRITE] > 0))
1004 || ((grp->active_channels[CTCM_WRITE] == 0) &&
1005 (grp->active_channels[CTCM_READ] > 0)))
1006 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1009 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1010 "exit %s: %i / Grp:%s total_channels=%i, active_channels: "
1011 "read=%i, write=%i\n", __func__, action,
1012 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
1013 grp->active_channels[CTCM_READ],
1014 grp->active_channels[CTCM_WRITE]);
1016 CTCM_PR_DEBUG("exit %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
1020 * Unpack a just received skb and hand it over to
1022 * special MPC version of unpack_skb.
1024 * ch The channel where this skb has been received.
1025 * pskb The received skb.
1027 static void ctcmpc_unpack_skb(struct channel *ch, struct sk_buff *pskb)
1029 struct net_device *dev = ch->netdev;
1030 struct ctcm_priv *priv = dev->ml_priv;
1031 struct mpc_group *grp = priv->mpcg;
1032 struct pdu *curr_pdu;
1033 struct mpcg_info *mpcginfo;
1034 struct th_header *header = NULL;
1035 struct th_sweep *sweep = NULL;
1036 int pdu_last_seen = 0;
1038 struct sk_buff *skb;
1042 CTCM_PR_DEBUG("ctcmpc enter: %s() %s cp:%i ch:%s\n",
1043 __func__, dev->name, smp_processor_id(), ch->id);
1045 header = (struct th_header *)pskb->data;
1046 if ((header->th_seg == 0) &&
1047 (header->th_ch_flag == 0) &&
1048 (header->th_blk_flag == 0) &&
1049 (header->th_seq_num == 0))
1050 /* nothing for us */ goto done;
1052 CTCM_PR_DBGDATA("%s: th_header\n", __func__);
1053 CTCM_D3_DUMP((char *)header, TH_HEADER_LENGTH);
1054 CTCM_PR_DBGDATA("%s: pskb len: %04x \n", __func__, pskb->len);
1057 pskb->ip_summed = CHECKSUM_UNNECESSARY;
1058 skb_pull(pskb, TH_HEADER_LENGTH);
1060 if (likely(header->th_ch_flag == TH_HAS_PDU)) {
1061 CTCM_PR_DBGDATA("%s: came into th_has_pdu\n", __func__);
1062 if ((fsm_getstate(grp->fsm) == MPCG_STATE_FLOWC) ||
1063 ((fsm_getstate(grp->fsm) == MPCG_STATE_READY) &&
1064 (header->th_seq_num != ch->th_seq_num + 1) &&
1065 (ch->th_seq_num != 0))) {
1066 /* This is NOT the next segment *
1067 * we are not the correct race winner *
1068 * go away and let someone else win *
1069 * BUT..this only applies if xid negot *
1072 grp->out_of_sequence += 1;
1073 __skb_push(pskb, TH_HEADER_LENGTH);
1074 skb_queue_tail(&ch->io_queue, pskb);
1075 CTCM_PR_DBGDATA("%s: th_seq_num expect:%08x "
1076 "got:%08x\n", __func__,
1077 ch->th_seq_num + 1, header->th_seq_num);
1081 grp->out_of_sequence = 0;
1082 ch->th_seq_num = header->th_seq_num;
1084 CTCM_PR_DBGDATA("ctcmpc: %s() FromVTAM_th_seq=%08x\n",
1085 __func__, ch->th_seq_num);
1087 if (unlikely(fsm_getstate(grp->fsm) != MPCG_STATE_READY))
1089 while ((pskb->len > 0) && !pdu_last_seen) {
1090 curr_pdu = (struct pdu *)pskb->data;
1092 CTCM_PR_DBGDATA("%s: pdu_header\n", __func__);
1093 CTCM_D3_DUMP((char *)pskb->data, PDU_HEADER_LENGTH);
1094 CTCM_PR_DBGDATA("%s: pskb len: %04x \n",
1095 __func__, pskb->len);
1097 skb_pull(pskb, PDU_HEADER_LENGTH);
1099 if (curr_pdu->pdu_flag & PDU_LAST)
1101 if (curr_pdu->pdu_flag & PDU_CNTL)
1102 pskb->protocol = htons(ETH_P_SNAP);
1104 pskb->protocol = htons(ETH_P_SNA_DIX);
1106 if ((pskb->len <= 0) || (pskb->len > ch->max_bufsize)) {
1107 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1108 "%s(%s): Dropping packet with "
1110 CTCM_FUNTAIL, dev->name, pskb->len);
1112 priv->stats.rx_dropped++;
1113 priv->stats.rx_length_errors++;
1116 skb_reset_mac_header(pskb);
1117 new_len = curr_pdu->pdu_offset;
1118 CTCM_PR_DBGDATA("%s: new_len: %04x \n",
1120 if ((new_len == 0) || (new_len > pskb->len)) {
1121 /* should never happen */
1122 /* pskb len must be hosed...bail out */
1123 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1124 "%s(%s): non valid pdu_offset: %04x",
1125 /* "data may be lost", */
1126 CTCM_FUNTAIL, dev->name, new_len);
1129 skb = __dev_alloc_skb(new_len+4, GFP_ATOMIC);
1132 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1133 "%s(%s): MEMORY allocation error",
1134 CTCM_FUNTAIL, dev->name);
1135 priv->stats.rx_dropped++;
1136 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1139 skb_put_data(skb, pskb->data, new_len);
1141 skb_reset_mac_header(skb);
1142 skb->dev = pskb->dev;
1143 skb->protocol = pskb->protocol;
1144 skb->ip_summed = CHECKSUM_UNNECESSARY;
1145 *((__u32 *) skb_push(skb, 4)) = ch->pdu_seq;
1148 if (do_debug_data) {
1149 ctcm_pr_debug("%s: ToDCM_pdu_seq= %08x\n",
1150 __func__, ch->pdu_seq);
1151 ctcm_pr_debug("%s: skb:%0lx "
1152 "skb len: %d \n", __func__,
1153 (unsigned long)skb, skb->len);
1154 ctcm_pr_debug("%s: up to 32 bytes "
1155 "of pdu_data sent\n", __func__);
1156 ctcmpc_dump32((char *)skb->data, skb->len);
1160 sendrc = netif_rx(skb);
1161 priv->stats.rx_packets++;
1162 priv->stats.rx_bytes += skblen;
1163 skb_pull(pskb, new_len); /* point to next PDU */
1166 mpcginfo = kmalloc(sizeof(struct mpcg_info), GFP_ATOMIC);
1167 if (mpcginfo == NULL)
1171 mpcginfo->th = header;
1172 mpcginfo->skb = pskb;
1173 CTCM_PR_DEBUG("%s: Not PDU - may be control pkt\n",
1176 sweep = (struct th_sweep *)pskb->data;
1177 mpcginfo->sweep = sweep;
1178 if (header->th_ch_flag == TH_SWEEP_REQ)
1179 mpc_rcvd_sweep_req(mpcginfo);
1180 else if (header->th_ch_flag == TH_SWEEP_RESP)
1181 mpc_rcvd_sweep_resp(mpcginfo);
1182 else if (header->th_blk_flag == TH_DATA_IS_XID) {
1183 struct xid2 *thisxid = (struct xid2 *)pskb->data;
1184 skb_pull(pskb, XID2_LENGTH);
1185 mpcginfo->xid = thisxid;
1186 fsm_event(grp->fsm, MPCG_EVENT_XID2, mpcginfo);
1187 } else if (header->th_blk_flag == TH_DISCONTACT)
1188 fsm_event(grp->fsm, MPCG_EVENT_DISCONC, mpcginfo);
1189 else if (header->th_seq_num != 0) {
1190 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1191 "%s(%s): control pkt expected\n",
1192 CTCM_FUNTAIL, dev->name);
1193 priv->stats.rx_dropped++;
1194 /* mpcginfo only used for non-data transfers */
1197 ctcmpc_dump_skb(pskb, -8);
1202 dev_kfree_skb_any(pskb);
1203 if (sendrc == NET_RX_DROP) {
1205 "The network backlog for %s is exceeded, "
1206 "package dropped\n", __func__);
1207 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1210 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1211 __func__, dev->name, ch, ch->id);
1215 * tasklet helper for mpc's skb unpacking.
1217 * ch The channel to work on.
1218 * Allow flow control back pressure to occur here.
1219 * Throttling back channel can result in excessive
1220 * channel inactivity and system deact of channel
1222 void ctcmpc_bh(unsigned long thischan)
1224 struct channel *ch = (struct channel *)thischan;
1225 struct sk_buff *skb;
1226 struct net_device *dev = ch->netdev;
1227 struct ctcm_priv *priv = dev->ml_priv;
1228 struct mpc_group *grp = priv->mpcg;
1230 CTCM_PR_DEBUG("%s cp:%i enter: %s() %s\n",
1231 dev->name, smp_processor_id(), __func__, ch->id);
1232 /* caller has requested driver to throttle back */
1233 while ((fsm_getstate(grp->fsm) != MPCG_STATE_FLOWC) &&
1234 (skb = skb_dequeue(&ch->io_queue))) {
1235 ctcmpc_unpack_skb(ch, skb);
1236 if (grp->out_of_sequence > 20) {
1237 /* assume data loss has occurred if */
1238 /* missing seq_num for extended */
1239 /* period of time */
1240 grp->out_of_sequence = 0;
1241 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1244 if (skb == skb_peek(&ch->io_queue))
1247 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1248 __func__, dev->name, ch, ch->id);
1253 * MPC Group Initializations
1255 struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv)
1257 struct mpc_group *grp;
1259 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
1260 "Enter %s(%p)", CTCM_FUNTAIL, priv);
1262 grp = kzalloc(sizeof(struct mpc_group), GFP_KERNEL);
1266 grp->fsm = init_fsm("mpcg", mpcg_state_names, mpcg_event_names,
1267 MPCG_NR_STATES, MPCG_NR_EVENTS, mpcg_fsm,
1268 mpcg_fsm_len, GFP_KERNEL);
1269 if (grp->fsm == NULL) {
1274 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1275 fsm_settimer(grp->fsm, &grp->timer);
1278 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC | GFP_DMA);
1279 if (grp->xid_skb == NULL) {
1280 kfree_fsm(grp->fsm);
1284 /* base xid for all channels in group */
1285 grp->xid_skb_data = grp->xid_skb->data;
1286 grp->xid_th = (struct th_header *)grp->xid_skb->data;
1287 skb_put_data(grp->xid_skb, &thnorm, TH_HEADER_LENGTH);
1289 grp->xid = (struct xid2 *)skb_tail_pointer(grp->xid_skb);
1290 skb_put_data(grp->xid_skb, &init_xid, XID2_LENGTH);
1291 grp->xid->xid2_adj_id = jiffies | 0xfff00000;
1292 grp->xid->xid2_sender_id = jiffies;
1294 grp->xid_id = skb_tail_pointer(grp->xid_skb);
1295 skb_put_data(grp->xid_skb, "VTAM", 4);
1298 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
1299 if (grp->rcvd_xid_skb == NULL) {
1300 kfree_fsm(grp->fsm);
1301 dev_kfree_skb(grp->xid_skb);
1305 grp->rcvd_xid_data = grp->rcvd_xid_skb->data;
1306 grp->rcvd_xid_th = (struct th_header *)grp->rcvd_xid_skb->data;
1307 skb_put_data(grp->rcvd_xid_skb, &thnorm, TH_HEADER_LENGTH);
1308 grp->saved_xid2 = NULL;
1309 priv->xid = grp->xid;
1315 * The MPC Group Station FSM
1319 * MPC Group Station FSM actions
1320 * CTCM_PROTO_MPC only
1324 * NOP action for statemachines
1326 static void mpc_action_nop(fsm_instance *fi, int event, void *arg)
1331 * invoked when the device transitions to dev_stopped
1332 * MPC will stop each individual channel if a single XID failure
1333 * occurs, or will intitiate all channels be stopped if a GROUP
1334 * level failure occurs.
1336 static void mpc_action_go_inop(fsm_instance *fi, int event, void *arg)
1338 struct net_device *dev = arg;
1339 struct ctcm_priv *priv;
1340 struct mpc_group *grp;
1341 struct channel *wch;
1343 CTCM_PR_DEBUG("Enter %s: %s\n", __func__, dev->name);
1345 priv = dev->ml_priv;
1347 grp->flow_off_called = 0;
1348 fsm_deltimer(&grp->timer);
1349 if (grp->channels_terminating)
1352 grp->channels_terminating = 1;
1353 grp->saved_state = fsm_getstate(grp->fsm);
1354 fsm_newstate(grp->fsm, MPCG_STATE_INOP);
1355 if (grp->saved_state > MPCG_STATE_XID7INITF)
1356 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1357 "%s(%s): MPC GROUP INOPERATIVE",
1358 CTCM_FUNTAIL, dev->name);
1359 if ((grp->saved_state != MPCG_STATE_RESET) ||
1360 /* dealloc_channel has been called */
1361 (grp->port_persist == 0))
1362 fsm_deltimer(&priv->restart_timer);
1364 wch = priv->channel[CTCM_WRITE];
1366 switch (grp->saved_state) {
1367 case MPCG_STATE_RESET:
1368 case MPCG_STATE_INOP:
1369 case MPCG_STATE_XID2INITW:
1370 case MPCG_STATE_XID0IOWAIT:
1371 case MPCG_STATE_XID2INITX:
1372 case MPCG_STATE_XID7INITW:
1373 case MPCG_STATE_XID7INITX:
1374 case MPCG_STATE_XID0IOWAIX:
1375 case MPCG_STATE_XID7INITI:
1376 case MPCG_STATE_XID7INITZ:
1377 case MPCG_STATE_XID7INITF:
1379 case MPCG_STATE_FLOWC:
1380 case MPCG_STATE_READY:
1382 tasklet_hi_schedule(&wch->ch_disc_tasklet);
1385 grp->xid2_tgnum = 0;
1386 grp->group_max_buflen = 0; /*min of all received */
1387 grp->outstanding_xid2 = 0;
1388 grp->outstanding_xid7 = 0;
1389 grp->outstanding_xid7_p2 = 0;
1390 grp->saved_xid2 = NULL;
1392 grp->changed_side = 0;
1394 grp->rcvd_xid_skb->data = grp->rcvd_xid_data;
1395 skb_reset_tail_pointer(grp->rcvd_xid_skb);
1396 grp->rcvd_xid_skb->len = 0;
1397 grp->rcvd_xid_th = (struct th_header *)grp->rcvd_xid_skb->data;
1398 skb_put_data(grp->rcvd_xid_skb, &thnorm, TH_HEADER_LENGTH);
1400 if (grp->send_qllc_disc == 1) {
1401 grp->send_qllc_disc = 0;
1402 mpc_send_qllc_discontact(dev);
1405 /* DO NOT issue DEV_EVENT_STOP directly out of this code */
1406 /* This can result in INOP of VTAM PU due to halting of */
1407 /* outstanding IO which causes a sense to be returned */
1408 /* Only about 3 senses are allowed and then IOS/VTAM will*/
1409 /* become unreachable without manual intervention */
1410 if ((grp->port_persist == 1) || (grp->alloc_called)) {
1411 grp->alloc_called = 0;
1412 fsm_deltimer(&priv->restart_timer);
1413 fsm_addtimer(&priv->restart_timer, 500, DEV_EVENT_RESTART, dev);
1414 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1415 if (grp->saved_state > MPCG_STATE_XID7INITF)
1416 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ALWAYS,
1417 "%s(%s): MPC GROUP RECOVERY SCHEDULED",
1418 CTCM_FUNTAIL, dev->name);
1420 fsm_deltimer(&priv->restart_timer);
1421 fsm_addtimer(&priv->restart_timer, 500, DEV_EVENT_STOP, dev);
1422 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1423 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ALWAYS,
1424 "%s(%s): NO MPC GROUP RECOVERY ATTEMPTED",
1425 CTCM_FUNTAIL, dev->name);
1430 * Handle mpc group action timeout.
1431 * MPC Group Station FSM action
1432 * CTCM_PROTO_MPC only
1434 * fi An instance of an mpc_group fsm.
1435 * event The event, just happened.
1436 * arg Generic pointer, casted from net_device * upon call.
1438 static void mpc_action_timeout(fsm_instance *fi, int event, void *arg)
1440 struct net_device *dev = arg;
1441 struct ctcm_priv *priv;
1442 struct mpc_group *grp;
1443 struct channel *wch;
1444 struct channel *rch;
1446 priv = dev->ml_priv;
1448 wch = priv->channel[CTCM_WRITE];
1449 rch = priv->channel[CTCM_READ];
1451 switch (fsm_getstate(grp->fsm)) {
1452 case MPCG_STATE_XID2INITW:
1453 /* Unless there is outstanding IO on the */
1454 /* channel just return and wait for ATTN */
1455 /* interrupt to begin XID negotiations */
1456 if ((fsm_getstate(rch->fsm) == CH_XID0_PENDING) &&
1457 (fsm_getstate(wch->fsm) == CH_XID0_PENDING))
1461 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1464 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1466 CTCM_FUNTAIL, dev->name);
1471 * MPC Group Station FSM action
1472 * CTCM_PROTO_MPC only
1474 void mpc_action_discontact(fsm_instance *fi, int event, void *arg)
1476 struct mpcg_info *mpcginfo = arg;
1477 struct channel *ch = mpcginfo->ch;
1478 struct net_device *dev;
1479 struct ctcm_priv *priv;
1480 struct mpc_group *grp;
1485 priv = dev->ml_priv;
1487 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1489 CTCM_FUNTAIL, dev->name, ch->id);
1491 grp->send_qllc_disc = 1;
1492 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1501 * MPC Group Station - not part of FSM
1502 * CTCM_PROTO_MPC only
1503 * called from add_channel in ctcm_main.c
1505 void mpc_action_send_discontact(unsigned long thischan)
1508 struct channel *ch = (struct channel *)thischan;
1509 unsigned long saveflags = 0;
1511 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1512 rc = ccw_device_start(ch->cdev, &ch->ccw[15], 0, 0xff, 0);
1513 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1516 ctcm_ccw_check_rc(ch, rc, (char *)__func__);
1524 * helper function of mpc FSM
1525 * CTCM_PROTO_MPC only
1526 * mpc_action_rcvd_xid7
1528 static int mpc_validate_xid(struct mpcg_info *mpcginfo)
1530 struct channel *ch = mpcginfo->ch;
1531 struct net_device *dev = ch->netdev;
1532 struct ctcm_priv *priv = dev->ml_priv;
1533 struct mpc_group *grp = priv->mpcg;
1534 struct xid2 *xid = mpcginfo->xid;
1538 int len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1540 CTCM_PR_DEBUG("Enter %s: xid=%p\n", __func__, xid);
1544 /* XID REJECTED: xid == NULL */
1545 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1546 "%s(%s): xid = NULL",
1547 CTCM_FUNTAIL, ch->id);
1551 CTCM_D3_DUMP((char *)xid, XID2_LENGTH);
1553 /*the received direction should be the opposite of ours */
1554 if (((CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? XID2_WRITE_SIDE :
1555 XID2_READ_SIDE) != xid->xid2_dlc_type) {
1557 /* XID REJECTED: r/w channel pairing mismatch */
1558 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1559 "%s(%s): r/w channel pairing mismatch",
1560 CTCM_FUNTAIL, ch->id);
1564 if (xid->xid2_dlc_type == XID2_READ_SIDE) {
1565 CTCM_PR_DEBUG("%s: grpmaxbuf:%d xid2buflen:%d\n", __func__,
1566 grp->group_max_buflen, xid->xid2_buf_len);
1568 if (grp->group_max_buflen == 0 || grp->group_max_buflen >
1569 xid->xid2_buf_len - len)
1570 grp->group_max_buflen = xid->xid2_buf_len - len;
1573 if (grp->saved_xid2 == NULL) {
1575 (struct xid2 *)skb_tail_pointer(grp->rcvd_xid_skb);
1577 skb_put_data(grp->rcvd_xid_skb, xid, XID2_LENGTH);
1578 grp->rcvd_xid_skb->data = grp->rcvd_xid_data;
1580 skb_reset_tail_pointer(grp->rcvd_xid_skb);
1581 grp->rcvd_xid_skb->len = 0;
1583 /* convert two 32 bit numbers into 1 64 bit for id compare */
1584 our_id = (__u64)priv->xid->xid2_adj_id;
1585 our_id = our_id << 32;
1586 our_id = our_id + priv->xid->xid2_sender_id;
1587 their_id = (__u64)xid->xid2_adj_id;
1588 their_id = their_id << 32;
1589 their_id = their_id + xid->xid2_sender_id;
1590 /* lower id assume the xside role */
1591 if (our_id < their_id) {
1593 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1594 "%s(%s): WE HAVE LOW ID - TAKE XSIDE",
1595 CTCM_FUNTAIL, ch->id);
1598 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1599 "%s(%s): WE HAVE HIGH ID - TAKE YSIDE",
1600 CTCM_FUNTAIL, ch->id);
1604 if (xid->xid2_flag4 != grp->saved_xid2->xid2_flag4) {
1606 /* XID REJECTED: xid flag byte4 mismatch */
1607 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1608 "%s(%s): xid flag byte4 mismatch",
1609 CTCM_FUNTAIL, ch->id);
1611 if (xid->xid2_flag2 == 0x40) {
1613 /* XID REJECTED - xid NOGOOD */
1614 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1615 "%s(%s): xid NOGOOD",
1616 CTCM_FUNTAIL, ch->id);
1618 if (xid->xid2_adj_id != grp->saved_xid2->xid2_adj_id) {
1620 /* XID REJECTED - Adjacent Station ID Mismatch */
1621 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1622 "%s(%s): Adjacent Station ID Mismatch",
1623 CTCM_FUNTAIL, ch->id);
1625 if (xid->xid2_sender_id != grp->saved_xid2->xid2_sender_id) {
1627 /* XID REJECTED - Sender Address Mismatch */
1628 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1629 "%s(%s): Sender Address Mismatch",
1630 CTCM_FUNTAIL, ch->id);
1636 "The XID used in the MPC protocol is not valid, "
1638 priv->xid->xid2_flag2 = 0x40;
1639 grp->saved_xid2->xid2_flag2 = 0x40;
1646 * MPC Group Station FSM action
1647 * CTCM_PROTO_MPC only
1649 static void mpc_action_side_xid(fsm_instance *fsm, void *arg, int side)
1651 struct channel *ch = arg;
1654 unsigned long saveflags = 0; /* avoids compiler warning with
1655 spin_unlock_irqrestore */
1657 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1658 __func__, smp_processor_id(), ch, ch->id);
1660 if (ctcm_checkalloc_buffer(ch))
1664 * skb data-buffer referencing:
1666 ch->trans_skb->data = ch->trans_skb_data;
1667 skb_reset_tail_pointer(ch->trans_skb);
1668 ch->trans_skb->len = 0;
1669 /* result of the previous 3 statements is NOT always
1670 * already set after ctcm_checkalloc_buffer
1671 * because of possible reuse of the trans_skb
1673 memset(ch->trans_skb->data, 0, 16);
1674 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1675 /* check is main purpose here: */
1676 skb_put(ch->trans_skb, TH_HEADER_LENGTH);
1677 ch->rcvd_xid = (struct xid2 *)skb_tail_pointer(ch->trans_skb);
1678 /* check is main purpose here: */
1679 skb_put(ch->trans_skb, XID2_LENGTH);
1680 ch->rcvd_xid_id = skb_tail_pointer(ch->trans_skb);
1681 /* cleanup back to startpoint */
1682 ch->trans_skb->data = ch->trans_skb_data;
1683 skb_reset_tail_pointer(ch->trans_skb);
1684 ch->trans_skb->len = 0;
1686 /* non-checking rewrite of above skb data-buffer referencing: */
1688 memset(ch->trans_skb->data, 0, 16);
1689 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1690 ch->rcvd_xid = (struct xid2 *)(ch->trans_skb_data + TH_HEADER_LENGTH);
1691 ch->rcvd_xid_id = ch->trans_skb_data + TH_HEADER_LENGTH + XID2_LENGTH;
1694 ch->ccw[8].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1695 ch->ccw[8].count = 0;
1696 ch->ccw[8].cda = 0x00;
1698 if (!(ch->xid_th && ch->xid && ch->xid_id))
1699 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_INFO,
1700 "%s(%s): xid_th=%p, xid=%p, xid_id=%p",
1701 CTCM_FUNTAIL, ch->id, ch->xid_th, ch->xid, ch->xid_id);
1703 if (side == XSIDE) {
1704 /* mpc_action_xside_xid */
1705 if (ch->xid_th == NULL)
1707 ch->ccw[9].cmd_code = CCW_CMD_WRITE;
1708 ch->ccw[9].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1709 ch->ccw[9].count = TH_HEADER_LENGTH;
1710 ch->ccw[9].cda = virt_to_phys(ch->xid_th);
1712 if (ch->xid == NULL)
1714 ch->ccw[10].cmd_code = CCW_CMD_WRITE;
1715 ch->ccw[10].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1716 ch->ccw[10].count = XID2_LENGTH;
1717 ch->ccw[10].cda = virt_to_phys(ch->xid);
1719 ch->ccw[11].cmd_code = CCW_CMD_READ;
1720 ch->ccw[11].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1721 ch->ccw[11].count = TH_HEADER_LENGTH;
1722 ch->ccw[11].cda = virt_to_phys(ch->rcvd_xid_th);
1724 ch->ccw[12].cmd_code = CCW_CMD_READ;
1725 ch->ccw[12].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1726 ch->ccw[12].count = XID2_LENGTH;
1727 ch->ccw[12].cda = virt_to_phys(ch->rcvd_xid);
1729 ch->ccw[13].cmd_code = CCW_CMD_READ;
1730 ch->ccw[13].cda = virt_to_phys(ch->rcvd_xid_id);
1732 } else { /* side == YSIDE : mpc_action_yside_xid */
1733 ch->ccw[9].cmd_code = CCW_CMD_READ;
1734 ch->ccw[9].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1735 ch->ccw[9].count = TH_HEADER_LENGTH;
1736 ch->ccw[9].cda = virt_to_phys(ch->rcvd_xid_th);
1738 ch->ccw[10].cmd_code = CCW_CMD_READ;
1739 ch->ccw[10].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1740 ch->ccw[10].count = XID2_LENGTH;
1741 ch->ccw[10].cda = virt_to_phys(ch->rcvd_xid);
1743 if (ch->xid_th == NULL)
1745 ch->ccw[11].cmd_code = CCW_CMD_WRITE;
1746 ch->ccw[11].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1747 ch->ccw[11].count = TH_HEADER_LENGTH;
1748 ch->ccw[11].cda = virt_to_phys(ch->xid_th);
1750 if (ch->xid == NULL)
1752 ch->ccw[12].cmd_code = CCW_CMD_WRITE;
1753 ch->ccw[12].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1754 ch->ccw[12].count = XID2_LENGTH;
1755 ch->ccw[12].cda = virt_to_phys(ch->xid);
1757 if (ch->xid_id == NULL)
1759 ch->ccw[13].cmd_code = CCW_CMD_WRITE;
1760 ch->ccw[13].cda = virt_to_phys(ch->xid_id);
1763 ch->ccw[13].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1764 ch->ccw[13].count = 4;
1766 ch->ccw[14].cmd_code = CCW_CMD_NOOP;
1767 ch->ccw[14].flags = CCW_FLAG_SLI;
1768 ch->ccw[14].count = 0;
1769 ch->ccw[14].cda = 0;
1771 CTCM_CCW_DUMP((char *)&ch->ccw[8], sizeof(struct ccw1) * 7);
1772 CTCM_D3_DUMP((char *)ch->xid_th, TH_HEADER_LENGTH);
1773 CTCM_D3_DUMP((char *)ch->xid, XID2_LENGTH);
1774 CTCM_D3_DUMP((char *)ch->xid_id, 4);
1776 if (!in_hardirq()) {
1777 /* Such conditional locking is a known problem for
1778 * sparse because its static undeterministic.
1779 * Warnings should be ignored here. */
1780 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1784 fsm_addtimer(&ch->timer, 5000 , CTC_EVENT_TIMER, ch);
1785 rc = ccw_device_start(ch->cdev, &ch->ccw[8], 0, 0xff, 0);
1787 if (gotlock) /* see remark above about conditional locking */
1788 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1791 ctcm_ccw_check_rc(ch, rc,
1792 (side == XSIDE) ? "x-side XID" : "y-side XID");
1796 CTCM_PR_DEBUG("Exit %s: ch=0x%p id=%s\n",
1797 __func__, ch, ch->id);
1803 * MPC Group Station FSM action
1804 * CTCM_PROTO_MPC only
1806 static void mpc_action_xside_xid(fsm_instance *fsm, int event, void *arg)
1808 mpc_action_side_xid(fsm, arg, XSIDE);
1812 * MPC Group Station FSM action
1813 * CTCM_PROTO_MPC only
1815 static void mpc_action_yside_xid(fsm_instance *fsm, int event, void *arg)
1817 mpc_action_side_xid(fsm, arg, YSIDE);
1821 * MPC Group Station FSM action
1822 * CTCM_PROTO_MPC only
1824 static void mpc_action_doxid0(fsm_instance *fsm, int event, void *arg)
1826 struct channel *ch = arg;
1827 struct net_device *dev = ch->netdev;
1828 struct ctcm_priv *priv = dev->ml_priv;
1829 struct mpc_group *grp = priv->mpcg;
1831 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1832 __func__, smp_processor_id(), ch, ch->id);
1834 if (ch->xid == NULL) {
1835 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1836 "%s(%s): ch->xid == NULL",
1837 CTCM_FUNTAIL, dev->name);
1841 fsm_newstate(ch->fsm, CH_XID0_INPROGRESS);
1843 ch->xid->xid2_option = XID2_0;
1845 switch (fsm_getstate(grp->fsm)) {
1846 case MPCG_STATE_XID2INITW:
1847 case MPCG_STATE_XID2INITX:
1848 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1850 case MPCG_STATE_XID0IOWAIT:
1851 case MPCG_STATE_XID0IOWAIX:
1852 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1856 fsm_event(grp->fsm, MPCG_EVENT_DOIO, ch);
1862 * MPC Group Station FSM action
1863 * CTCM_PROTO_MPC only
1865 static void mpc_action_doxid7(fsm_instance *fsm, int event, void *arg)
1867 struct net_device *dev = arg;
1868 struct ctcm_priv *priv = dev->ml_priv;
1869 struct mpc_group *grp = NULL;
1878 for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
1879 struct channel *ch = priv->channel[direction];
1880 struct xid2 *thisxid = ch->xid;
1881 ch->xid_skb->data = ch->xid_skb_data;
1882 skb_reset_tail_pointer(ch->xid_skb);
1883 ch->xid_skb->len = 0;
1884 thisxid->xid2_option = XID2_7;
1888 if (grp->outstanding_xid7_p2 > 0) {
1889 if (grp->roll == YSIDE) {
1890 if (fsm_getstate(ch->fsm) == CH_XID7_PENDING1) {
1891 fsm_newstate(ch->fsm, CH_XID7_PENDING2);
1892 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1893 skb_put_data(ch->xid_skb, &thdummy,
1897 } else if (fsm_getstate(ch->fsm) < CH_XID7_PENDING2) {
1898 fsm_newstate(ch->fsm, CH_XID7_PENDING2);
1899 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1900 skb_put_data(ch->xid_skb, &thnorm,
1906 if (grp->roll == YSIDE) {
1907 if (fsm_getstate(ch->fsm) < CH_XID7_PENDING4) {
1908 fsm_newstate(ch->fsm, CH_XID7_PENDING4);
1909 skb_put_data(ch->xid_skb, &thnorm,
1911 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1914 } else if (fsm_getstate(ch->fsm) == CH_XID7_PENDING3) {
1915 fsm_newstate(ch->fsm, CH_XID7_PENDING4);
1916 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1917 skb_put_data(ch->xid_skb, &thdummy,
1924 fsm_event(grp->fsm, MPCG_EVENT_DOIO, ch);
1931 * MPC Group Station FSM action
1932 * CTCM_PROTO_MPC only
1934 static void mpc_action_rcvd_xid0(fsm_instance *fsm, int event, void *arg)
1937 struct mpcg_info *mpcginfo = arg;
1938 struct channel *ch = mpcginfo->ch;
1939 struct net_device *dev = ch->netdev;
1940 struct ctcm_priv *priv = dev->ml_priv;
1941 struct mpc_group *grp = priv->mpcg;
1943 CTCM_PR_DEBUG("%s: ch-id:%s xid2:%i xid7:%i xidt_p2:%i \n",
1944 __func__, ch->id, grp->outstanding_xid2,
1945 grp->outstanding_xid7, grp->outstanding_xid7_p2);
1947 if (fsm_getstate(ch->fsm) < CH_XID7_PENDING)
1948 fsm_newstate(ch->fsm, CH_XID7_PENDING);
1950 grp->outstanding_xid2--;
1951 grp->outstanding_xid7++;
1952 grp->outstanding_xid7_p2++;
1954 /* must change state before validating xid to */
1955 /* properly handle interim interrupts received*/
1956 switch (fsm_getstate(grp->fsm)) {
1957 case MPCG_STATE_XID2INITW:
1958 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITX);
1959 mpc_validate_xid(mpcginfo);
1961 case MPCG_STATE_XID0IOWAIT:
1962 fsm_newstate(grp->fsm, MPCG_STATE_XID0IOWAIX);
1963 mpc_validate_xid(mpcginfo);
1965 case MPCG_STATE_XID2INITX:
1966 if (grp->outstanding_xid2 == 0) {
1967 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITW);
1968 mpc_validate_xid(mpcginfo);
1969 fsm_event(grp->fsm, MPCG_EVENT_XID2DONE, dev);
1972 case MPCG_STATE_XID0IOWAIX:
1973 if (grp->outstanding_xid2 == 0) {
1974 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITI);
1975 mpc_validate_xid(mpcginfo);
1976 fsm_event(grp->fsm, MPCG_EVENT_XID2DONE, dev);
1982 CTCM_PR_DEBUG("ctcmpc:%s() %s xid2:%i xid7:%i xidt_p2:%i \n",
1983 __func__, ch->id, grp->outstanding_xid2,
1984 grp->outstanding_xid7, grp->outstanding_xid7_p2);
1985 CTCM_PR_DEBUG("ctcmpc:%s() %s grpstate: %s chanstate: %s \n",
1987 fsm_getstate_str(grp->fsm), fsm_getstate_str(ch->fsm));
1994 * MPC Group Station FSM action
1995 * CTCM_PROTO_MPC only
1997 static void mpc_action_rcvd_xid7(fsm_instance *fsm, int event, void *arg)
1999 struct mpcg_info *mpcginfo = arg;
2000 struct channel *ch = mpcginfo->ch;
2001 struct net_device *dev = ch->netdev;
2002 struct ctcm_priv *priv = dev->ml_priv;
2003 struct mpc_group *grp = priv->mpcg;
2005 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
2006 __func__, smp_processor_id(), ch, ch->id);
2007 CTCM_PR_DEBUG("%s: outstanding_xid7: %i, outstanding_xid7_p2: %i\n",
2008 __func__, grp->outstanding_xid7, grp->outstanding_xid7_p2);
2010 grp->outstanding_xid7--;
2011 ch->xid_skb->data = ch->xid_skb_data;
2012 skb_reset_tail_pointer(ch->xid_skb);
2013 ch->xid_skb->len = 0;
2015 switch (fsm_getstate(grp->fsm)) {
2016 case MPCG_STATE_XID7INITI:
2017 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITZ);
2018 mpc_validate_xid(mpcginfo);
2020 case MPCG_STATE_XID7INITW:
2021 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITX);
2022 mpc_validate_xid(mpcginfo);
2024 case MPCG_STATE_XID7INITZ:
2025 case MPCG_STATE_XID7INITX:
2026 if (grp->outstanding_xid7 == 0) {
2027 if (grp->outstanding_xid7_p2 > 0) {
2028 grp->outstanding_xid7 =
2029 grp->outstanding_xid7_p2;
2030 grp->outstanding_xid7_p2 = 0;
2032 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITF);
2034 mpc_validate_xid(mpcginfo);
2035 fsm_event(grp->fsm, MPCG_EVENT_XID7DONE, dev);
2038 mpc_validate_xid(mpcginfo);
2046 * mpc_action helper of an MPC Group Station FSM action
2047 * CTCM_PROTO_MPC only
2049 static int mpc_send_qllc_discontact(struct net_device *dev)
2051 struct sk_buff *skb;
2052 struct qllc *qllcptr;
2053 struct ctcm_priv *priv = dev->ml_priv;
2054 struct mpc_group *grp = priv->mpcg;
2056 CTCM_PR_DEBUG("%s: GROUP STATE: %s\n",
2057 __func__, mpcg_state_names[grp->saved_state]);
2059 switch (grp->saved_state) {
2061 * establish conn callback function is
2062 * preferred method to report failure
2064 case MPCG_STATE_XID0IOWAIT:
2065 case MPCG_STATE_XID0IOWAIX:
2066 case MPCG_STATE_XID7INITI:
2067 case MPCG_STATE_XID7INITZ:
2068 case MPCG_STATE_XID2INITW:
2069 case MPCG_STATE_XID2INITX:
2070 case MPCG_STATE_XID7INITW:
2071 case MPCG_STATE_XID7INITX:
2072 if (grp->estconnfunc) {
2073 grp->estconnfunc(grp->port_num, -1, 0);
2074 grp->estconnfunc = NULL;
2078 case MPCG_STATE_FLOWC:
2079 case MPCG_STATE_READY:
2080 grp->send_qllc_disc = 2;
2082 skb = __dev_alloc_skb(sizeof(struct qllc), GFP_ATOMIC);
2084 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2085 "%s(%s): skb allocation error",
2086 CTCM_FUNTAIL, dev->name);
2087 priv->stats.rx_dropped++;
2091 qllcptr = skb_put(skb, sizeof(struct qllc));
2092 qllcptr->qllc_address = 0xcc;
2093 qllcptr->qllc_commands = 0x03;
2095 if (skb_headroom(skb) < 4) {
2096 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2097 "%s(%s): skb_headroom error",
2098 CTCM_FUNTAIL, dev->name);
2099 dev_kfree_skb_any(skb);
2103 *((__u32 *)skb_push(skb, 4)) =
2104 priv->channel[CTCM_READ]->pdu_seq;
2105 priv->channel[CTCM_READ]->pdu_seq++;
2106 CTCM_PR_DBGDATA("ctcmpc: %s ToDCM_pdu_seq= %08x\n",
2107 __func__, priv->channel[CTCM_READ]->pdu_seq);
2109 /* receipt of CC03 resets anticipated sequence number on
2111 priv->channel[CTCM_READ]->pdu_seq = 0x00;
2112 skb_reset_mac_header(skb);
2114 skb->protocol = htons(ETH_P_SNAP);
2115 skb->ip_summed = CHECKSUM_UNNECESSARY;
2117 CTCM_D3_DUMP(skb->data, (sizeof(struct qllc) + 4));
2128 /* --- This is the END my friend --- */