2 * drivers/s390/net/ctcm_mpc.c
4 * Copyright IBM Corp. 2004, 2007
5 * Authors: Belinda Thompson (belindat@us.ibm.com)
6 * Andy Richter (richtera@us.ibm.com)
7 * Peter Tiedemann (ptiedem@de.ibm.com)
11 This module exports functions to be used by CCS:
12 EXPORT_SYMBOL(ctc_mpc_alloc_channel);
13 EXPORT_SYMBOL(ctc_mpc_establish_connectivity);
14 EXPORT_SYMBOL(ctc_mpc_dealloc_ch);
15 EXPORT_SYMBOL(ctc_mpc_flow_control);
22 #include <linux/version.h>
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 #include <linux/errno.h>
28 #include <linux/types.h>
29 #include <linux/interrupt.h>
30 #include <linux/timer.h>
31 #include <linux/sched.h>
33 #include <linux/signal.h>
34 #include <linux/string.h>
35 #include <linux/proc_fs.h>
38 #include <linux/if_arp.h>
39 #include <linux/tcp.h>
40 #include <linux/skbuff.h>
41 #include <linux/ctype.h>
42 #include <linux/netdevice.h>
45 #include <linux/io.h> /* instead of <asm/io.h> ok ? */
46 #include <asm/ccwdev.h>
47 #include <asm/ccwgroup.h>
48 #include <linux/bitops.h> /* instead of <asm/bitops.h> ok ? */
49 #include <linux/uaccess.h> /* instead of <asm/uaccess.h> ok ? */
50 #include <linux/wait.h>
51 #include <linux/moduleparam.h>
52 #include <asm/idals.h>
56 #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];
134 #if (UTS_MACHINE == s390x)
140 char bhex[82], duphex[82];
149 for (ct = 0; ct < len; ct++, ptr++, rptr++) {
151 #if (UTS_MACHINE == s390x)
152 sprintf(addr, "%16.16lx", (__u64)rptr);
154 sprintf(addr, "%8.8X", (__u32)rptr);
157 sprintf(boff, "%4.4X", (__u32)ct);
161 if ((sw == 4) || (sw == 12))
166 #if (UTS_MACHINE == s390x)
167 sprintf(tbuf, "%2.2lX", (__u64)*ptr);
169 sprintf(tbuf, "%2.2X", (__u32)*ptr);
174 if ((0 != isprint(*ptr)) && (*ptr >= 0x20))
184 if ((strcmp(duphex, bhex)) != 0) {
187 "Duplicate as above to %s", addr);
188 ctcm_pr_debug(" --- %s ---\n",
191 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
192 addr, boff, bhex, basc);
194 strcpy(duphex, bhex);
203 for ( ; rm > 0; rm--, sw++) {
204 if ((sw == 4) || (sw == 12))
212 sprintf(tdup, "Duplicate as above to %s", addr);
213 ctcm_pr_debug(" --- %s ---\n", tdup);
215 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
216 addr, boff, bhex, basc);
219 sprintf(tdup, "Duplicate as above to %s", addr);
220 ctcm_pr_debug(" --- %s ---\n", tdup);
223 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
224 addr, boff, bhex, basc);
230 } /* end of ctcmpc_dumpit */
235 * Dump header and first 16 bytes of an sk_buff for debugging purposes.
237 * skb The sk_buff to dump.
238 * offset Offset relative to skb-data, where to start the dump.
240 void ctcmpc_dump_skb(struct sk_buff *skb, int offset)
243 struct th_header *header;
252 header = (struct th_header *)p;
254 ctcm_pr_debug("dump:\n");
255 ctcm_pr_debug("skb len=%d \n", skb->len);
257 switch (header->th_ch_flag) {
262 if ((header->th_blk_flag == TH_DATA_IS_XID) &&
263 (header->th_is_xid == 0x01))
273 pheader = (struct pdu *)p;
274 ctcm_pr_debug("pdu->offset: %d hex: %04x\n",
275 pheader->pdu_offset, pheader->pdu_offset);
276 ctcm_pr_debug("pdu->flag : %02x\n", pheader->pdu_flag);
277 ctcm_pr_debug("pdu->proto : %02x\n", pheader->pdu_proto);
278 ctcm_pr_debug("pdu->seq : %02x\n", pheader->pdu_seq);
282 ctcm_pr_debug("th->seg : %02x\n", header->th_seg);
283 ctcm_pr_debug("th->ch : %02x\n", header->th_ch_flag);
284 ctcm_pr_debug("th->blk_flag: %02x\n", header->th_blk_flag);
285 ctcm_pr_debug("th->type : %s\n",
286 (header->th_is_xid) ? "DATA" : "XID");
287 ctcm_pr_debug("th->seqnum : %04x\n", header->th_seq_num);
293 ctcm_pr_debug("data: ");
294 for (i = 0; i < bl; i++)
295 ctcm_pr_debug("%02x%s", *p++, (i % 16) ? " " : "\n");
300 static struct net_device *ctcmpc_get_dev(int port_num)
303 struct net_device *dev;
304 struct ctcm_priv *priv;
306 sprintf(device, "%s%i", MPC_DEVICE_NAME, port_num);
308 dev = __dev_get_by_name(&init_net, device);
311 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
312 "%s: Device not found by name: %s",
313 CTCM_FUNTAIL, device);
318 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
319 "%s(%s): dev->ml_priv is NULL",
320 CTCM_FUNTAIL, device);
323 if (priv->mpcg == NULL) {
324 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
325 "%s(%s): priv->mpcg is NULL",
326 CTCM_FUNTAIL, device);
333 * ctc_mpc_alloc_channel
334 * (exported interface)
336 * Device Initialization :
337 * ACTPATH driven IO operations
339 int ctc_mpc_alloc_channel(int port_num, void (*callback)(int, int))
341 struct net_device *dev;
342 struct mpc_group *grp;
343 struct ctcm_priv *priv;
345 dev = ctcmpc_get_dev(port_num);
351 grp->allochanfunc = callback;
352 grp->port_num = port_num;
353 grp->port_persist = 1;
355 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
357 CTCM_FUNTAIL, dev->name, fsm_getstate_str(grp->fsm));
359 switch (fsm_getstate(grp->fsm)) {
360 case MPCG_STATE_INOP:
361 /* Group is in the process of terminating */
362 grp->alloc_called = 1;
364 case MPCG_STATE_RESET:
365 /* MPC Group will transition to state */
366 /* MPCG_STATE_XID2INITW iff the minimum number */
367 /* of 1 read and 1 write channel have successfully*/
369 /*fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);*/
371 grp->send_qllc_disc = 1;
372 case MPCG_STATE_XID0IOWAIT:
373 fsm_deltimer(&grp->timer);
374 grp->outstanding_xid2 = 0;
375 grp->outstanding_xid7 = 0;
376 grp->outstanding_xid7_p2 = 0;
377 grp->saved_xid2 = NULL;
380 fsm_event(priv->fsm, DEV_EVENT_START, dev);
382 case MPCG_STATE_READY:
383 /* XID exchanges completed after PORT was activated */
384 /* Link station already active */
385 /* Maybe timing issue...retry callback */
386 grp->allocchan_callback_retries++;
387 if (grp->allocchan_callback_retries < 4) {
388 if (grp->allochanfunc)
389 grp->allochanfunc(grp->port_num,
390 grp->group_max_buflen);
392 /* there are problems...bail out */
393 /* there may be a state mismatch so restart */
394 grp->port_persist = 1;
395 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
396 grp->allocchan_callback_retries = 0;
403 EXPORT_SYMBOL(ctc_mpc_alloc_channel);
406 * ctc_mpc_establish_connectivity
407 * (exported interface)
409 void ctc_mpc_establish_connectivity(int port_num,
410 void (*callback)(int, int, int))
412 struct net_device *dev;
413 struct mpc_group *grp;
414 struct ctcm_priv *priv;
415 struct channel *rch, *wch;
417 dev = ctcmpc_get_dev(port_num);
422 rch = priv->channel[READ];
423 wch = priv->channel[WRITE];
425 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
427 CTCM_FUNTAIL, dev->name, fsm_getstate_str(grp->fsm));
429 grp->estconnfunc = callback;
430 grp->port_num = port_num;
432 switch (fsm_getstate(grp->fsm)) {
433 case MPCG_STATE_READY:
434 /* XID exchanges completed after PORT was activated */
435 /* Link station already active */
436 /* Maybe timing issue...retry callback */
437 fsm_deltimer(&grp->timer);
438 grp->estconn_callback_retries++;
439 if (grp->estconn_callback_retries < 4) {
440 if (grp->estconnfunc) {
441 grp->estconnfunc(grp->port_num, 0,
442 grp->group_max_buflen);
443 grp->estconnfunc = NULL;
446 /* there are problems...bail out */
447 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
448 grp->estconn_callback_retries = 0;
451 case MPCG_STATE_INOP:
452 case MPCG_STATE_RESET:
453 /* MPC Group is not ready to start XID - min num of */
454 /* 1 read and 1 write channel have not been acquired*/
456 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
457 "%s(%s): REJECTED - inactive channels",
458 CTCM_FUNTAIL, dev->name);
459 if (grp->estconnfunc) {
460 grp->estconnfunc(grp->port_num, -1, 0);
461 grp->estconnfunc = NULL;
464 case MPCG_STATE_XID2INITW:
465 /* alloc channel was called but no XID exchange */
466 /* has occurred. initiate xside XID exchange */
467 /* make sure yside XID0 processing has not started */
469 if ((fsm_getstate(rch->fsm) > CH_XID0_PENDING) ||
470 (fsm_getstate(wch->fsm) > CH_XID0_PENDING)) {
471 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
472 "%s(%s): ABORT - PASSIVE XID",
473 CTCM_FUNTAIL, dev->name);
476 grp->send_qllc_disc = 1;
477 fsm_newstate(grp->fsm, MPCG_STATE_XID0IOWAIT);
478 fsm_deltimer(&grp->timer);
479 fsm_addtimer(&grp->timer, MPC_XID_TIMEOUT_VALUE,
480 MPCG_EVENT_TIMER, dev);
481 grp->outstanding_xid7 = 0;
482 grp->outstanding_xid7_p2 = 0;
483 grp->saved_xid2 = NULL;
484 if ((rch->in_mpcgroup) &&
485 (fsm_getstate(rch->fsm) == CH_XID0_PENDING))
486 fsm_event(grp->fsm, MPCG_EVENT_XID0DO, rch);
488 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
489 "%s(%s): RX-%s not ready for ACTIVE XID0",
490 CTCM_FUNTAIL, dev->name, rch->id);
491 if (grp->estconnfunc) {
492 grp->estconnfunc(grp->port_num, -1, 0);
493 grp->estconnfunc = NULL;
495 fsm_deltimer(&grp->timer);
498 if ((wch->in_mpcgroup) &&
499 (fsm_getstate(wch->fsm) == CH_XID0_PENDING))
500 fsm_event(grp->fsm, MPCG_EVENT_XID0DO, wch);
502 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
503 "%s(%s): WX-%s not ready for ACTIVE XID0",
504 CTCM_FUNTAIL, dev->name, wch->id);
505 if (grp->estconnfunc) {
506 grp->estconnfunc(grp->port_num, -1, 0);
507 grp->estconnfunc = NULL;
509 fsm_deltimer(&grp->timer);
513 case MPCG_STATE_XID0IOWAIT:
514 /* already in active XID negotiations */
520 CTCM_PR_DEBUG("Exit %s()\n", __func__);
523 EXPORT_SYMBOL(ctc_mpc_establish_connectivity);
527 * (exported interface)
529 void ctc_mpc_dealloc_ch(int port_num)
531 struct net_device *dev;
532 struct ctcm_priv *priv;
533 struct mpc_group *grp;
535 dev = ctcmpc_get_dev(port_num);
541 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_DEBUG,
542 "%s: %s: refcount = %d\n",
543 CTCM_FUNTAIL, dev->name, atomic_read(&dev->refcnt));
545 fsm_deltimer(&priv->restart_timer);
546 grp->channels_terminating = 0;
547 fsm_deltimer(&grp->timer);
548 grp->allochanfunc = NULL;
549 grp->estconnfunc = NULL;
550 grp->port_persist = 0;
551 grp->send_qllc_disc = 0;
552 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
557 EXPORT_SYMBOL(ctc_mpc_dealloc_ch);
560 * ctc_mpc_flow_control
561 * (exported interface)
563 void ctc_mpc_flow_control(int port_num, int flowc)
565 struct ctcm_priv *priv;
566 struct mpc_group *grp;
567 struct net_device *dev;
571 dev = ctcmpc_get_dev(port_num);
577 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
578 "%s: %s: flowc = %d",
579 CTCM_FUNTAIL, dev->name, flowc);
581 rch = priv->channel[READ];
583 mpcg_state = fsm_getstate(grp->fsm);
586 if (mpcg_state == MPCG_STATE_FLOWC)
588 if (mpcg_state == MPCG_STATE_READY) {
589 if (grp->flow_off_called == 1)
590 grp->flow_off_called = 0;
592 fsm_newstate(grp->fsm, MPCG_STATE_FLOWC);
597 if (mpcg_state == MPCG_STATE_FLOWC) {
598 fsm_newstate(grp->fsm, MPCG_STATE_READY);
599 /* ensure any data that has accumulated */
600 /* on the io_queue will now be sen t */
601 tasklet_schedule(&rch->ch_tasklet);
603 /* possible race condition */
604 if (mpcg_state == MPCG_STATE_READY) {
605 grp->flow_off_called = 1;
612 EXPORT_SYMBOL(ctc_mpc_flow_control);
614 static int mpc_send_qllc_discontact(struct net_device *);
617 * helper function of ctcmpc_unpack_skb
619 static void mpc_rcvd_sweep_resp(struct mpcg_info *mpcginfo)
621 struct channel *rch = mpcginfo->ch;
622 struct net_device *dev = rch->netdev;
623 struct ctcm_priv *priv = dev->ml_priv;
624 struct mpc_group *grp = priv->mpcg;
625 struct channel *ch = priv->channel[WRITE];
627 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, ch, ch->id);
628 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
630 grp->sweep_rsp_pend_num--;
632 if ((grp->sweep_req_pend_num == 0) &&
633 (grp->sweep_rsp_pend_num == 0)) {
634 fsm_deltimer(&ch->sweep_timer);
636 rch->th_seq_num = 0x00;
637 ch->th_seq_num = 0x00;
638 ctcm_clear_busy_do(dev);
648 * helper function of mpc_rcvd_sweep_req
649 * which is a helper of ctcmpc_unpack_skb
651 static void ctcmpc_send_sweep_resp(struct channel *rch)
653 struct net_device *dev = rch->netdev;
654 struct ctcm_priv *priv = dev->ml_priv;
655 struct mpc_group *grp = priv->mpcg;
657 struct th_sweep *header;
658 struct sk_buff *sweep_skb;
659 struct channel *ch = priv->channel[WRITE];
661 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, rch, rch->id);
663 sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC | GFP_DMA);
664 if (sweep_skb == NULL) {
665 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
666 "%s(%s): sweep_skb allocation ERROR\n",
667 CTCM_FUNTAIL, rch->id);
672 header = (struct th_sweep *)
673 kmalloc(sizeof(struct th_sweep), gfp_type());
676 dev_kfree_skb_any(sweep_skb);
681 header->th.th_seg = 0x00 ;
682 header->th.th_ch_flag = TH_SWEEP_RESP;
683 header->th.th_blk_flag = 0x00;
684 header->th.th_is_xid = 0x00;
685 header->th.th_seq_num = 0x00;
686 header->sw.th_last_seq = ch->th_seq_num;
688 memcpy(skb_put(sweep_skb, TH_SWEEP_LENGTH), header, TH_SWEEP_LENGTH);
692 dev->trans_start = jiffies;
693 skb_queue_tail(&ch->sweep_queue, sweep_skb);
695 fsm_addtimer(&ch->sweep_timer, 100, CTC_EVENT_RSWEEP_TIMER, ch);
702 ctcm_clear_busy_do(dev);
703 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
710 * helper function of ctcmpc_unpack_skb
712 static void mpc_rcvd_sweep_req(struct mpcg_info *mpcginfo)
714 struct channel *rch = mpcginfo->ch;
715 struct net_device *dev = rch->netdev;
716 struct ctcm_priv *priv = dev->ml_priv;
717 struct mpc_group *grp = priv->mpcg;
718 struct channel *ch = priv->channel[WRITE];
721 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
722 " %s(): ch=0x%p id=%s\n", __func__, ch, ch->id);
724 if (grp->in_sweep == 0) {
726 ctcm_test_and_set_busy(dev);
727 grp->sweep_req_pend_num = grp->active_channels[READ];
728 grp->sweep_rsp_pend_num = grp->active_channels[READ];
731 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
733 grp->sweep_req_pend_num--;
734 ctcmpc_send_sweep_resp(ch);
740 * MPC Group Station FSM definitions
742 static const char *mpcg_event_names[] = {
743 [MPCG_EVENT_INOP] = "INOP Condition",
744 [MPCG_EVENT_DISCONC] = "Discontact Received",
745 [MPCG_EVENT_XID0DO] = "Channel Active - Start XID",
746 [MPCG_EVENT_XID2] = "XID2 Received",
747 [MPCG_EVENT_XID2DONE] = "XID0 Complete",
748 [MPCG_EVENT_XID7DONE] = "XID7 Complete",
749 [MPCG_EVENT_TIMER] = "XID Setup Timer",
750 [MPCG_EVENT_DOIO] = "XID DoIO",
753 static const char *mpcg_state_names[] = {
754 [MPCG_STATE_RESET] = "Reset",
755 [MPCG_STATE_INOP] = "INOP",
756 [MPCG_STATE_XID2INITW] = "Passive XID- XID0 Pending Start",
757 [MPCG_STATE_XID2INITX] = "Passive XID- XID0 Pending Complete",
758 [MPCG_STATE_XID7INITW] = "Passive XID- XID7 Pending P1 Start",
759 [MPCG_STATE_XID7INITX] = "Passive XID- XID7 Pending P2 Complete",
760 [MPCG_STATE_XID0IOWAIT] = "Active XID- XID0 Pending Start",
761 [MPCG_STATE_XID0IOWAIX] = "Active XID- XID0 Pending Complete",
762 [MPCG_STATE_XID7INITI] = "Active XID- XID7 Pending Start",
763 [MPCG_STATE_XID7INITZ] = "Active XID- XID7 Pending Complete ",
764 [MPCG_STATE_XID7INITF] = "XID - XID7 Complete ",
765 [MPCG_STATE_FLOWC] = "FLOW CONTROL ON",
766 [MPCG_STATE_READY] = "READY",
770 * The MPC Group Station FSM
773 static const fsm_node mpcg_fsm[] = {
774 { MPCG_STATE_RESET, MPCG_EVENT_INOP, mpc_action_go_inop },
775 { MPCG_STATE_INOP, MPCG_EVENT_INOP, mpc_action_nop },
776 { MPCG_STATE_FLOWC, MPCG_EVENT_INOP, mpc_action_go_inop },
778 { MPCG_STATE_READY, MPCG_EVENT_DISCONC, mpc_action_discontact },
779 { MPCG_STATE_READY, MPCG_EVENT_INOP, mpc_action_go_inop },
781 { MPCG_STATE_XID2INITW, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
782 { MPCG_STATE_XID2INITW, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
783 { MPCG_STATE_XID2INITW, MPCG_EVENT_INOP, mpc_action_go_inop },
784 { MPCG_STATE_XID2INITW, MPCG_EVENT_TIMER, mpc_action_timeout },
785 { MPCG_STATE_XID2INITW, MPCG_EVENT_DOIO, mpc_action_yside_xid },
787 { MPCG_STATE_XID2INITX, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
788 { MPCG_STATE_XID2INITX, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
789 { MPCG_STATE_XID2INITX, MPCG_EVENT_INOP, mpc_action_go_inop },
790 { MPCG_STATE_XID2INITX, MPCG_EVENT_TIMER, mpc_action_timeout },
791 { MPCG_STATE_XID2INITX, MPCG_EVENT_DOIO, mpc_action_yside_xid },
793 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID2DONE, mpc_action_doxid7 },
794 { MPCG_STATE_XID7INITW, MPCG_EVENT_DISCONC, mpc_action_discontact },
795 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
796 { MPCG_STATE_XID7INITW, MPCG_EVENT_INOP, mpc_action_go_inop },
797 { MPCG_STATE_XID7INITW, MPCG_EVENT_TIMER, mpc_action_timeout },
798 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
799 { MPCG_STATE_XID7INITW, MPCG_EVENT_DOIO, mpc_action_yside_xid },
801 { MPCG_STATE_XID7INITX, MPCG_EVENT_DISCONC, mpc_action_discontact },
802 { MPCG_STATE_XID7INITX, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
803 { MPCG_STATE_XID7INITX, MPCG_EVENT_INOP, mpc_action_go_inop },
804 { MPCG_STATE_XID7INITX, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
805 { MPCG_STATE_XID7INITX, MPCG_EVENT_TIMER, mpc_action_timeout },
806 { MPCG_STATE_XID7INITX, MPCG_EVENT_DOIO, mpc_action_yside_xid },
808 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
809 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_DISCONC, mpc_action_discontact },
810 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
811 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_INOP, mpc_action_go_inop },
812 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_TIMER, mpc_action_timeout },
813 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_DOIO, mpc_action_xside_xid },
815 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
816 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_DISCONC, mpc_action_discontact },
817 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
818 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_INOP, mpc_action_go_inop },
819 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_TIMER, mpc_action_timeout },
820 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_DOIO, mpc_action_xside_xid },
822 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID2DONE, mpc_action_doxid7 },
823 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
824 { MPCG_STATE_XID7INITI, MPCG_EVENT_DISCONC, mpc_action_discontact },
825 { MPCG_STATE_XID7INITI, MPCG_EVENT_INOP, mpc_action_go_inop },
826 { MPCG_STATE_XID7INITI, MPCG_EVENT_TIMER, mpc_action_timeout },
827 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
828 { MPCG_STATE_XID7INITI, MPCG_EVENT_DOIO, mpc_action_xside_xid },
830 { MPCG_STATE_XID7INITZ, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
831 { MPCG_STATE_XID7INITZ, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
832 { MPCG_STATE_XID7INITZ, MPCG_EVENT_DISCONC, mpc_action_discontact },
833 { MPCG_STATE_XID7INITZ, MPCG_EVENT_INOP, mpc_action_go_inop },
834 { MPCG_STATE_XID7INITZ, MPCG_EVENT_TIMER, mpc_action_timeout },
835 { MPCG_STATE_XID7INITZ, MPCG_EVENT_DOIO, mpc_action_xside_xid },
837 { MPCG_STATE_XID7INITF, MPCG_EVENT_INOP, mpc_action_go_inop },
838 { MPCG_STATE_XID7INITF, MPCG_EVENT_XID7DONE, mpc_action_go_ready },
841 static int mpcg_fsm_len = ARRAY_SIZE(mpcg_fsm);
844 * MPC Group Station FSM action
845 * CTCM_PROTO_MPC only
847 static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg)
849 struct net_device *dev = arg;
850 struct ctcm_priv *priv = dev->ml_priv;
851 struct mpc_group *grp = priv->mpcg;
854 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
855 "%s(%s): No MPC group",
856 CTCM_FUNTAIL, dev->name);
860 fsm_deltimer(&grp->timer);
862 if (grp->saved_xid2->xid2_flag2 == 0x40) {
863 priv->xid->xid2_flag2 = 0x00;
864 if (grp->estconnfunc) {
865 grp->estconnfunc(grp->port_num, 1,
866 grp->group_max_buflen);
867 grp->estconnfunc = NULL;
868 } else if (grp->allochanfunc)
869 grp->send_qllc_disc = 1;
871 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
872 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
874 CTCM_FUNTAIL, dev->name);
878 grp->port_persist = 1;
879 grp->out_of_sequence = 0;
880 grp->estconn_called = 0;
882 tasklet_hi_schedule(&grp->mpc_tasklet2);
888 * helper of ctcm_init_netdevice
889 * CTCM_PROTO_MPC only
891 void mpc_group_ready(unsigned long adev)
893 struct net_device *dev = (struct net_device *)adev;
894 struct ctcm_priv *priv = dev->ml_priv;
895 struct mpc_group *grp = priv->mpcg;
896 struct channel *ch = NULL;
899 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
900 "%s(%s): No MPC group",
901 CTCM_FUNTAIL, dev->name);
905 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
906 "%s: %s: GROUP TRANSITIONED TO READY, maxbuf = %d\n",
907 CTCM_FUNTAIL, dev->name, grp->group_max_buflen);
909 fsm_newstate(grp->fsm, MPCG_STATE_READY);
911 /* Put up a read on the channel */
912 ch = priv->channel[READ];
914 CTCM_PR_DBGDATA("ctcmpc: %s() ToDCM_pdu_seq= %08x\n" ,
915 __func__, ch->pdu_seq);
917 ctcmpc_chx_rxidle(ch->fsm, CTC_EVENT_START, ch);
918 /* Put the write channel in idle state */
919 ch = priv->channel[WRITE];
920 if (ch->collect_len > 0) {
921 spin_lock(&ch->collect_lock);
922 ctcm_purge_skb_queue(&ch->collect_queue);
924 spin_unlock(&ch->collect_lock);
926 ctcm_chx_txidle(ch->fsm, CTC_EVENT_START, ch);
927 ctcm_clear_busy(dev);
929 if (grp->estconnfunc) {
930 grp->estconnfunc(grp->port_num, 0,
931 grp->group_max_buflen);
932 grp->estconnfunc = NULL;
933 } else if (grp->allochanfunc)
934 grp->allochanfunc(grp->port_num, grp->group_max_buflen);
936 grp->send_qllc_disc = 1;
937 grp->changed_side = 0;
944 * Increment the MPC Group Active Channel Counts
945 * helper of dev_action (called from channel fsm)
947 void mpc_channel_action(struct channel *ch, int direction, int action)
949 struct net_device *dev = ch->netdev;
950 struct ctcm_priv *priv = dev->ml_priv;
951 struct mpc_group *grp = priv->mpcg;
954 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
955 "%s(%s): No MPC group",
956 CTCM_FUNTAIL, dev->name);
960 CTCM_PR_DEBUG("enter %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
962 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
963 "%s: %i / Grp:%s total_channels=%i, active_channels: "
964 "read=%i, write=%i\n", __func__, action,
965 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
966 grp->active_channels[READ], grp->active_channels[WRITE]);
968 if ((action == MPC_CHANNEL_ADD) && (ch->in_mpcgroup == 0)) {
969 grp->num_channel_paths++;
970 grp->active_channels[direction]++;
971 grp->outstanding_xid2++;
974 if (ch->xid_skb != NULL)
975 dev_kfree_skb_any(ch->xid_skb);
977 ch->xid_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT,
978 GFP_ATOMIC | GFP_DMA);
979 if (ch->xid_skb == NULL) {
980 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
981 "%s(%s): Couldn't alloc ch xid_skb\n",
982 CTCM_FUNTAIL, dev->name);
983 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
986 ch->xid_skb_data = ch->xid_skb->data;
987 ch->xid_th = (struct th_header *)ch->xid_skb->data;
988 skb_put(ch->xid_skb, TH_HEADER_LENGTH);
989 ch->xid = (struct xid2 *)skb_tail_pointer(ch->xid_skb);
990 skb_put(ch->xid_skb, XID2_LENGTH);
991 ch->xid_id = skb_tail_pointer(ch->xid_skb);
992 ch->xid_skb->data = ch->xid_skb_data;
993 skb_reset_tail_pointer(ch->xid_skb);
994 ch->xid_skb->len = 0;
996 memcpy(skb_put(ch->xid_skb, grp->xid_skb->len),
1000 ch->xid->xid2_dlc_type = ((CHANNEL_DIRECTION(ch->flags) == READ)
1001 ? XID2_READ_SIDE : XID2_WRITE_SIDE);
1003 if (CHANNEL_DIRECTION(ch->flags) == WRITE)
1004 ch->xid->xid2_buf_len = 0x00;
1006 ch->xid_skb->data = ch->xid_skb_data;
1007 skb_reset_tail_pointer(ch->xid_skb);
1008 ch->xid_skb->len = 0;
1010 fsm_newstate(ch->fsm, CH_XID0_PENDING);
1012 if ((grp->active_channels[READ] > 0) &&
1013 (grp->active_channels[WRITE] > 0) &&
1014 (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) {
1015 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);
1016 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
1017 "%s: %s: MPC GROUP CHANNELS ACTIVE\n",
1018 __func__, dev->name);
1020 } else if ((action == MPC_CHANNEL_REMOVE) &&
1021 (ch->in_mpcgroup == 1)) {
1022 ch->in_mpcgroup = 0;
1023 grp->num_channel_paths--;
1024 grp->active_channels[direction]--;
1026 if (ch->xid_skb != NULL)
1027 dev_kfree_skb_any(ch->xid_skb);
1030 if (grp->channels_terminating)
1033 if (((grp->active_channels[READ] == 0) &&
1034 (grp->active_channels[WRITE] > 0))
1035 || ((grp->active_channels[WRITE] == 0) &&
1036 (grp->active_channels[READ] > 0)))
1037 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1040 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1041 "exit %s: %i / Grp:%s total_channels=%i, active_channels: "
1042 "read=%i, write=%i\n", __func__, action,
1043 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
1044 grp->active_channels[READ], grp->active_channels[WRITE]);
1046 CTCM_PR_DEBUG("exit %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
1050 * Unpack a just received skb and hand it over to
1052 * special MPC version of unpack_skb.
1054 * ch The channel where this skb has been received.
1055 * pskb The received skb.
1057 static void ctcmpc_unpack_skb(struct channel *ch, struct sk_buff *pskb)
1059 struct net_device *dev = ch->netdev;
1060 struct ctcm_priv *priv = dev->ml_priv;
1061 struct mpc_group *grp = priv->mpcg;
1062 struct pdu *curr_pdu;
1063 struct mpcg_info *mpcginfo;
1064 struct th_header *header = NULL;
1065 struct th_sweep *sweep = NULL;
1066 int pdu_last_seen = 0;
1068 struct sk_buff *skb;
1072 CTCM_PR_DEBUG("ctcmpc enter: %s() %s cp:%i ch:%s\n",
1073 __func__, dev->name, smp_processor_id(), ch->id);
1075 header = (struct th_header *)pskb->data;
1076 if ((header->th_seg == 0) &&
1077 (header->th_ch_flag == 0) &&
1078 (header->th_blk_flag == 0) &&
1079 (header->th_seq_num == 0))
1080 /* nothing for us */ goto done;
1082 CTCM_PR_DBGDATA("%s: th_header\n", __func__);
1083 CTCM_D3_DUMP((char *)header, TH_HEADER_LENGTH);
1084 CTCM_PR_DBGDATA("%s: pskb len: %04x \n", __func__, pskb->len);
1087 pskb->ip_summed = CHECKSUM_UNNECESSARY;
1088 skb_pull(pskb, TH_HEADER_LENGTH);
1090 if (likely(header->th_ch_flag == TH_HAS_PDU)) {
1091 CTCM_PR_DBGDATA("%s: came into th_has_pdu\n", __func__);
1092 if ((fsm_getstate(grp->fsm) == MPCG_STATE_FLOWC) ||
1093 ((fsm_getstate(grp->fsm) == MPCG_STATE_READY) &&
1094 (header->th_seq_num != ch->th_seq_num + 1) &&
1095 (ch->th_seq_num != 0))) {
1096 /* This is NOT the next segment *
1097 * we are not the correct race winner *
1098 * go away and let someone else win *
1099 * BUT..this only applies if xid negot *
1102 grp->out_of_sequence += 1;
1103 __skb_push(pskb, TH_HEADER_LENGTH);
1104 skb_queue_tail(&ch->io_queue, pskb);
1105 CTCM_PR_DBGDATA("%s: th_seq_num expect:%08x "
1106 "got:%08x\n", __func__,
1107 ch->th_seq_num + 1, header->th_seq_num);
1111 grp->out_of_sequence = 0;
1112 ch->th_seq_num = header->th_seq_num;
1114 CTCM_PR_DBGDATA("ctcmpc: %s() FromVTAM_th_seq=%08x\n",
1115 __func__, ch->th_seq_num);
1117 if (unlikely(fsm_getstate(grp->fsm) != MPCG_STATE_READY))
1120 while ((pskb->len > 0) && !pdu_last_seen) {
1121 curr_pdu = (struct pdu *)pskb->data;
1123 CTCM_PR_DBGDATA("%s: pdu_header\n", __func__);
1124 CTCM_D3_DUMP((char *)pskb->data, PDU_HEADER_LENGTH);
1125 CTCM_PR_DBGDATA("%s: pskb len: %04x \n",
1126 __func__, pskb->len);
1128 skb_pull(pskb, PDU_HEADER_LENGTH);
1130 if (curr_pdu->pdu_flag & PDU_LAST)
1132 if (curr_pdu->pdu_flag & PDU_CNTL)
1133 pskb->protocol = htons(ETH_P_SNAP);
1135 pskb->protocol = htons(ETH_P_SNA_DIX);
1137 if ((pskb->len <= 0) || (pskb->len > ch->max_bufsize)) {
1138 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1139 "%s(%s): Dropping packet with "
1141 CTCM_FUNTAIL, dev->name, pskb->len);
1143 priv->stats.rx_dropped++;
1144 priv->stats.rx_length_errors++;
1147 skb_reset_mac_header(pskb);
1148 new_len = curr_pdu->pdu_offset;
1149 CTCM_PR_DBGDATA("%s: new_len: %04x \n",
1151 if ((new_len == 0) || (new_len > pskb->len)) {
1152 /* should never happen */
1153 /* pskb len must be hosed...bail out */
1154 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1155 "%s(%s): non valid pdu_offset: %04x",
1156 /* "data may be lost", */
1157 CTCM_FUNTAIL, dev->name, new_len);
1160 skb = __dev_alloc_skb(new_len+4, GFP_ATOMIC);
1163 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1164 "%s(%s): MEMORY allocation error",
1165 CTCM_FUNTAIL, dev->name);
1166 priv->stats.rx_dropped++;
1167 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1170 memcpy(skb_put(skb, new_len), pskb->data, new_len);
1172 skb_reset_mac_header(skb);
1173 skb->dev = pskb->dev;
1174 skb->protocol = pskb->protocol;
1175 skb->ip_summed = CHECKSUM_UNNECESSARY;
1176 *((__u32 *) skb_push(skb, 4)) = ch->pdu_seq;
1179 if (do_debug_data) {
1180 ctcm_pr_debug("%s: ToDCM_pdu_seq= %08x\n",
1181 __func__, ch->pdu_seq);
1182 ctcm_pr_debug("%s: skb:%0lx "
1183 "skb len: %d \n", __func__,
1184 (unsigned long)skb, skb->len);
1185 ctcm_pr_debug("%s: up to 32 bytes "
1186 "of pdu_data sent\n", __func__);
1187 ctcmpc_dump32((char *)skb->data, skb->len);
1191 sendrc = netif_rx(skb);
1192 priv->stats.rx_packets++;
1193 priv->stats.rx_bytes += skblen;
1194 skb_pull(pskb, new_len); /* point to next PDU */
1197 mpcginfo = (struct mpcg_info *)
1198 kmalloc(sizeof(struct mpcg_info), gfp_type());
1199 if (mpcginfo == NULL)
1203 mpcginfo->th = header;
1204 mpcginfo->skb = pskb;
1205 CTCM_PR_DEBUG("%s: Not PDU - may be control pkt\n",
1208 sweep = (struct th_sweep *)pskb->data;
1209 mpcginfo->sweep = sweep;
1210 if (header->th_ch_flag == TH_SWEEP_REQ)
1211 mpc_rcvd_sweep_req(mpcginfo);
1212 else if (header->th_ch_flag == TH_SWEEP_RESP)
1213 mpc_rcvd_sweep_resp(mpcginfo);
1214 else if (header->th_blk_flag == TH_DATA_IS_XID) {
1215 struct xid2 *thisxid = (struct xid2 *)pskb->data;
1216 skb_pull(pskb, XID2_LENGTH);
1217 mpcginfo->xid = thisxid;
1218 fsm_event(grp->fsm, MPCG_EVENT_XID2, mpcginfo);
1219 } else if (header->th_blk_flag == TH_DISCONTACT)
1220 fsm_event(grp->fsm, MPCG_EVENT_DISCONC, mpcginfo);
1221 else if (header->th_seq_num != 0) {
1222 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1223 "%s(%s): control pkt expected\n",
1224 CTCM_FUNTAIL, dev->name);
1225 priv->stats.rx_dropped++;
1226 /* mpcginfo only used for non-data transfers */
1229 ctcmpc_dump_skb(pskb, -8);
1234 dev_kfree_skb_any(pskb);
1235 if (sendrc == NET_RX_DROP) {
1236 printk(KERN_WARNING "%s %s() NETWORK BACKLOG EXCEEDED"
1237 " - PACKET DROPPED\n", dev->name, __func__);
1238 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1241 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1242 __func__, dev->name, ch, ch->id);
1246 * tasklet helper for mpc's skb unpacking.
1248 * ch The channel to work on.
1249 * Allow flow control back pressure to occur here.
1250 * Throttling back channel can result in excessive
1251 * channel inactivity and system deact of channel
1253 void ctcmpc_bh(unsigned long thischan)
1255 struct channel *ch = (struct channel *)thischan;
1256 struct sk_buff *skb;
1257 struct net_device *dev = ch->netdev;
1258 struct ctcm_priv *priv = dev->ml_priv;
1259 struct mpc_group *grp = priv->mpcg;
1261 CTCM_PR_DEBUG("%s cp:%i enter: %s() %s\n",
1262 dev->name, smp_processor_id(), __func__, ch->id);
1263 /* caller has requested driver to throttle back */
1264 while ((fsm_getstate(grp->fsm) != MPCG_STATE_FLOWC) &&
1265 (skb = skb_dequeue(&ch->io_queue))) {
1266 ctcmpc_unpack_skb(ch, skb);
1267 if (grp->out_of_sequence > 20) {
1268 /* assume data loss has occurred if */
1269 /* missing seq_num for extended */
1270 /* period of time */
1271 grp->out_of_sequence = 0;
1272 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1275 if (skb == skb_peek(&ch->io_queue))
1278 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1279 __func__, dev->name, ch, ch->id);
1284 * MPC Group Initializations
1286 struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv)
1288 struct mpc_group *grp;
1290 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
1291 "Enter %s(%p)", CTCM_FUNTAIL, priv);
1293 grp = kzalloc(sizeof(struct mpc_group), GFP_KERNEL);
1297 grp->fsm = init_fsm("mpcg", mpcg_state_names, mpcg_event_names,
1298 MPCG_NR_STATES, MPCG_NR_EVENTS, mpcg_fsm,
1299 mpcg_fsm_len, GFP_KERNEL);
1300 if (grp->fsm == NULL) {
1305 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1306 fsm_settimer(grp->fsm, &grp->timer);
1309 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC | GFP_DMA);
1310 if (grp->xid_skb == NULL) {
1311 kfree_fsm(grp->fsm);
1315 /* base xid for all channels in group */
1316 grp->xid_skb_data = grp->xid_skb->data;
1317 grp->xid_th = (struct th_header *)grp->xid_skb->data;
1318 memcpy(skb_put(grp->xid_skb, TH_HEADER_LENGTH),
1319 &thnorm, TH_HEADER_LENGTH);
1321 grp->xid = (struct xid2 *)skb_tail_pointer(grp->xid_skb);
1322 memcpy(skb_put(grp->xid_skb, XID2_LENGTH), &init_xid, XID2_LENGTH);
1323 grp->xid->xid2_adj_id = jiffies | 0xfff00000;
1324 grp->xid->xid2_sender_id = jiffies;
1326 grp->xid_id = skb_tail_pointer(grp->xid_skb);
1327 memcpy(skb_put(grp->xid_skb, 4), "VTAM", 4);
1330 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
1331 if (grp->rcvd_xid_skb == NULL) {
1332 kfree_fsm(grp->fsm);
1333 dev_kfree_skb(grp->xid_skb);
1337 grp->rcvd_xid_data = grp->rcvd_xid_skb->data;
1338 grp->rcvd_xid_th = (struct th_header *)grp->rcvd_xid_skb->data;
1339 memcpy(skb_put(grp->rcvd_xid_skb, TH_HEADER_LENGTH),
1340 &thnorm, TH_HEADER_LENGTH);
1341 grp->saved_xid2 = NULL;
1342 priv->xid = grp->xid;
1348 * The MPC Group Station FSM
1352 * MPC Group Station FSM actions
1353 * CTCM_PROTO_MPC only
1357 * NOP action for statemachines
1359 static void mpc_action_nop(fsm_instance *fi, int event, void *arg)
1364 * invoked when the device transitions to dev_stopped
1365 * MPC will stop each individual channel if a single XID failure
1366 * occurs, or will intitiate all channels be stopped if a GROUP
1367 * level failure occurs.
1369 static void mpc_action_go_inop(fsm_instance *fi, int event, void *arg)
1371 struct net_device *dev = arg;
1372 struct ctcm_priv *priv;
1373 struct mpc_group *grp;
1375 struct channel *wch, *rch;
1377 BUG_ON(dev == NULL);
1378 CTCM_PR_DEBUG("Enter %s: %s\n", __func__, dev->name);
1380 priv = dev->ml_priv;
1382 grp->flow_off_called = 0;
1383 fsm_deltimer(&grp->timer);
1384 if (grp->channels_terminating)
1387 grp->channels_terminating = 1;
1388 grp->saved_state = fsm_getstate(grp->fsm);
1389 fsm_newstate(grp->fsm, MPCG_STATE_INOP);
1390 if (grp->saved_state > MPCG_STATE_XID7INITF)
1391 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1392 "%s(%s): MPC GROUP INOPERATIVE",
1393 CTCM_FUNTAIL, dev->name);
1394 if ((grp->saved_state != MPCG_STATE_RESET) ||
1395 /* dealloc_channel has been called */
1396 ((grp->saved_state == MPCG_STATE_RESET) &&
1397 (grp->port_persist == 0)))
1398 fsm_deltimer(&priv->restart_timer);
1400 wch = priv->channel[WRITE];
1401 rch = priv->channel[READ];
1403 switch (grp->saved_state) {
1404 case MPCG_STATE_RESET:
1405 case MPCG_STATE_INOP:
1406 case MPCG_STATE_XID2INITW:
1407 case MPCG_STATE_XID0IOWAIT:
1408 case MPCG_STATE_XID2INITX:
1409 case MPCG_STATE_XID7INITW:
1410 case MPCG_STATE_XID7INITX:
1411 case MPCG_STATE_XID0IOWAIX:
1412 case MPCG_STATE_XID7INITI:
1413 case MPCG_STATE_XID7INITZ:
1414 case MPCG_STATE_XID7INITF:
1416 case MPCG_STATE_FLOWC:
1417 case MPCG_STATE_READY:
1419 tasklet_hi_schedule(&wch->ch_disc_tasklet);
1422 grp->xid2_tgnum = 0;
1423 grp->group_max_buflen = 0; /*min of all received */
1424 grp->outstanding_xid2 = 0;
1425 grp->outstanding_xid7 = 0;
1426 grp->outstanding_xid7_p2 = 0;
1427 grp->saved_xid2 = NULL;
1429 grp->changed_side = 0;
1431 grp->rcvd_xid_skb->data = grp->rcvd_xid_data;
1432 skb_reset_tail_pointer(grp->rcvd_xid_skb);
1433 grp->rcvd_xid_skb->len = 0;
1434 grp->rcvd_xid_th = (struct th_header *)grp->rcvd_xid_skb->data;
1435 memcpy(skb_put(grp->rcvd_xid_skb, TH_HEADER_LENGTH), &thnorm,
1438 if (grp->send_qllc_disc == 1) {
1439 grp->send_qllc_disc = 0;
1440 rc = mpc_send_qllc_discontact(dev);
1443 /* DO NOT issue DEV_EVENT_STOP directly out of this code */
1444 /* This can result in INOP of VTAM PU due to halting of */
1445 /* outstanding IO which causes a sense to be returned */
1446 /* Only about 3 senses are allowed and then IOS/VTAM will*/
1447 /* become unreachable without manual intervention */
1448 if ((grp->port_persist == 1) || (grp->alloc_called)) {
1449 grp->alloc_called = 0;
1450 fsm_deltimer(&priv->restart_timer);
1451 fsm_addtimer(&priv->restart_timer, 500, DEV_EVENT_RESTART, dev);
1452 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1453 if (grp->saved_state > MPCG_STATE_XID7INITF)
1454 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ALWAYS,
1455 "%s(%s): MPC GROUP RECOVERY SCHEDULED",
1456 CTCM_FUNTAIL, dev->name);
1458 fsm_deltimer(&priv->restart_timer);
1459 fsm_addtimer(&priv->restart_timer, 500, DEV_EVENT_STOP, dev);
1460 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1461 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ALWAYS,
1462 "%s(%s): NO MPC GROUP RECOVERY ATTEMPTED",
1463 CTCM_FUNTAIL, dev->name);
1468 * Handle mpc group action timeout.
1469 * MPC Group Station FSM action
1470 * CTCM_PROTO_MPC only
1472 * fi An instance of an mpc_group fsm.
1473 * event The event, just happened.
1474 * arg Generic pointer, casted from net_device * upon call.
1476 static void mpc_action_timeout(fsm_instance *fi, int event, void *arg)
1478 struct net_device *dev = arg;
1479 struct ctcm_priv *priv;
1480 struct mpc_group *grp;
1481 struct channel *wch;
1482 struct channel *rch;
1484 BUG_ON(dev == NULL);
1486 priv = dev->ml_priv;
1488 wch = priv->channel[WRITE];
1489 rch = priv->channel[READ];
1491 switch (fsm_getstate(grp->fsm)) {
1492 case MPCG_STATE_XID2INITW:
1493 /* Unless there is outstanding IO on the */
1494 /* channel just return and wait for ATTN */
1495 /* interrupt to begin XID negotiations */
1496 if ((fsm_getstate(rch->fsm) == CH_XID0_PENDING) &&
1497 (fsm_getstate(wch->fsm) == CH_XID0_PENDING))
1500 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1503 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1505 CTCM_FUNTAIL, dev->name);
1510 * MPC Group Station FSM action
1511 * CTCM_PROTO_MPC only
1513 void mpc_action_discontact(fsm_instance *fi, int event, void *arg)
1515 struct mpcg_info *mpcginfo = arg;
1516 struct channel *ch = mpcginfo->ch;
1517 struct net_device *dev;
1518 struct ctcm_priv *priv;
1519 struct mpc_group *grp;
1524 priv = dev->ml_priv;
1526 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1528 CTCM_FUNTAIL, dev->name, ch->id);
1530 grp->send_qllc_disc = 1;
1531 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1540 * MPC Group Station - not part of FSM
1541 * CTCM_PROTO_MPC only
1542 * called from add_channel in ctcm_main.c
1544 void mpc_action_send_discontact(unsigned long thischan)
1547 struct channel *ch = (struct channel *)thischan;
1548 unsigned long saveflags = 0;
1550 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1551 rc = ccw_device_start(ch->cdev, &ch->ccw[15],
1552 (unsigned long)ch, 0xff, 0);
1553 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1556 ctcm_ccw_check_rc(ch, rc, (char *)__func__);
1564 * helper function of mpc FSM
1565 * CTCM_PROTO_MPC only
1566 * mpc_action_rcvd_xid7
1568 static int mpc_validate_xid(struct mpcg_info *mpcginfo)
1570 struct channel *ch = mpcginfo->ch;
1571 struct net_device *dev = ch->netdev;
1572 struct ctcm_priv *priv = dev->ml_priv;
1573 struct mpc_group *grp = priv->mpcg;
1574 struct xid2 *xid = mpcginfo->xid;
1578 int len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1580 CTCM_PR_DEBUG("Enter %s: xid=%p\n", __func__, xid);
1584 /* XID REJECTED: xid == NULL */
1585 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1586 "%s(%s): xid = NULL",
1587 CTCM_FUNTAIL, ch->id);
1591 CTCM_D3_DUMP((char *)xid, XID2_LENGTH);
1593 /*the received direction should be the opposite of ours */
1594 if (((CHANNEL_DIRECTION(ch->flags) == READ) ? XID2_WRITE_SIDE :
1595 XID2_READ_SIDE) != xid->xid2_dlc_type) {
1597 /* XID REJECTED: r/w channel pairing mismatch */
1598 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1599 "%s(%s): r/w channel pairing mismatch",
1600 CTCM_FUNTAIL, ch->id);
1604 if (xid->xid2_dlc_type == XID2_READ_SIDE) {
1605 CTCM_PR_DEBUG("%s: grpmaxbuf:%d xid2buflen:%d\n", __func__,
1606 grp->group_max_buflen, xid->xid2_buf_len);
1608 if (grp->group_max_buflen == 0 || grp->group_max_buflen >
1609 xid->xid2_buf_len - len)
1610 grp->group_max_buflen = xid->xid2_buf_len - len;
1613 if (grp->saved_xid2 == NULL) {
1615 (struct xid2 *)skb_tail_pointer(grp->rcvd_xid_skb);
1617 memcpy(skb_put(grp->rcvd_xid_skb,
1618 XID2_LENGTH), xid, XID2_LENGTH);
1619 grp->rcvd_xid_skb->data = grp->rcvd_xid_data;
1621 skb_reset_tail_pointer(grp->rcvd_xid_skb);
1622 grp->rcvd_xid_skb->len = 0;
1624 /* convert two 32 bit numbers into 1 64 bit for id compare */
1625 our_id = (__u64)priv->xid->xid2_adj_id;
1626 our_id = our_id << 32;
1627 our_id = our_id + priv->xid->xid2_sender_id;
1628 their_id = (__u64)xid->xid2_adj_id;
1629 their_id = their_id << 32;
1630 their_id = their_id + xid->xid2_sender_id;
1631 /* lower id assume the xside role */
1632 if (our_id < their_id) {
1634 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1635 "%s(%s): WE HAVE LOW ID - TAKE XSIDE",
1636 CTCM_FUNTAIL, ch->id);
1639 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1640 "%s(%s): WE HAVE HIGH ID - TAKE YSIDE",
1641 CTCM_FUNTAIL, ch->id);
1645 if (xid->xid2_flag4 != grp->saved_xid2->xid2_flag4) {
1647 /* XID REJECTED: xid flag byte4 mismatch */
1648 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1649 "%s(%s): xid flag byte4 mismatch",
1650 CTCM_FUNTAIL, ch->id);
1652 if (xid->xid2_flag2 == 0x40) {
1654 /* XID REJECTED - xid NOGOOD */
1655 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1656 "%s(%s): xid NOGOOD",
1657 CTCM_FUNTAIL, ch->id);
1659 if (xid->xid2_adj_id != grp->saved_xid2->xid2_adj_id) {
1661 /* XID REJECTED - Adjacent Station ID Mismatch */
1662 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1663 "%s(%s): Adjacent Station ID Mismatch",
1664 CTCM_FUNTAIL, ch->id);
1666 if (xid->xid2_sender_id != grp->saved_xid2->xid2_sender_id) {
1668 /* XID REJECTED - Sender Address Mismatch */
1669 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1670 "%s(%s): Sender Address Mismatch",
1671 CTCM_FUNTAIL, ch->id);
1677 ctcm_pr_info("ctcmpc : %s() failed\n", __FUNCTION__);
1678 priv->xid->xid2_flag2 = 0x40;
1679 grp->saved_xid2->xid2_flag2 = 0x40;
1686 * MPC Group Station FSM action
1687 * CTCM_PROTO_MPC only
1689 static void mpc_action_side_xid(fsm_instance *fsm, void *arg, int side)
1691 struct channel *ch = arg;
1694 unsigned long saveflags = 0; /* avoids compiler warning with
1695 spin_unlock_irqrestore */
1697 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1698 __func__, smp_processor_id(), ch, ch->id);
1700 if (ctcm_checkalloc_buffer(ch))
1704 * skb data-buffer referencing:
1706 ch->trans_skb->data = ch->trans_skb_data;
1707 skb_reset_tail_pointer(ch->trans_skb);
1708 ch->trans_skb->len = 0;
1709 /* result of the previous 3 statements is NOT always
1710 * already set after ctcm_checkalloc_buffer
1711 * because of possible reuse of the trans_skb
1713 memset(ch->trans_skb->data, 0, 16);
1714 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1715 /* check is main purpose here: */
1716 skb_put(ch->trans_skb, TH_HEADER_LENGTH);
1717 ch->rcvd_xid = (struct xid2 *)skb_tail_pointer(ch->trans_skb);
1718 /* check is main purpose here: */
1719 skb_put(ch->trans_skb, XID2_LENGTH);
1720 ch->rcvd_xid_id = skb_tail_pointer(ch->trans_skb);
1721 /* cleanup back to startpoint */
1722 ch->trans_skb->data = ch->trans_skb_data;
1723 skb_reset_tail_pointer(ch->trans_skb);
1724 ch->trans_skb->len = 0;
1726 /* non-checking rewrite of above skb data-buffer referencing: */
1728 memset(ch->trans_skb->data, 0, 16);
1729 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1730 ch->rcvd_xid = (struct xid2 *)(ch->trans_skb_data + TH_HEADER_LENGTH);
1731 ch->rcvd_xid_id = ch->trans_skb_data + TH_HEADER_LENGTH + XID2_LENGTH;
1734 ch->ccw[8].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1735 ch->ccw[8].count = 0;
1736 ch->ccw[8].cda = 0x00;
1738 if (!(ch->xid_th && ch->xid && ch->xid_id))
1739 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_INFO,
1740 "%s(%s): xid_th=%p, xid=%p, xid_id=%p",
1741 CTCM_FUNTAIL, ch->id, ch->xid_th, ch->xid, ch->xid_id);
1743 if (side == XSIDE) {
1744 /* mpc_action_xside_xid */
1745 if (ch->xid_th == NULL)
1747 ch->ccw[9].cmd_code = CCW_CMD_WRITE;
1748 ch->ccw[9].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1749 ch->ccw[9].count = TH_HEADER_LENGTH;
1750 ch->ccw[9].cda = virt_to_phys(ch->xid_th);
1752 if (ch->xid == NULL)
1754 ch->ccw[10].cmd_code = CCW_CMD_WRITE;
1755 ch->ccw[10].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1756 ch->ccw[10].count = XID2_LENGTH;
1757 ch->ccw[10].cda = virt_to_phys(ch->xid);
1759 ch->ccw[11].cmd_code = CCW_CMD_READ;
1760 ch->ccw[11].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1761 ch->ccw[11].count = TH_HEADER_LENGTH;
1762 ch->ccw[11].cda = virt_to_phys(ch->rcvd_xid_th);
1764 ch->ccw[12].cmd_code = CCW_CMD_READ;
1765 ch->ccw[12].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1766 ch->ccw[12].count = XID2_LENGTH;
1767 ch->ccw[12].cda = virt_to_phys(ch->rcvd_xid);
1769 ch->ccw[13].cmd_code = CCW_CMD_READ;
1770 ch->ccw[13].cda = virt_to_phys(ch->rcvd_xid_id);
1772 } else { /* side == YSIDE : mpc_action_yside_xid */
1773 ch->ccw[9].cmd_code = CCW_CMD_READ;
1774 ch->ccw[9].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1775 ch->ccw[9].count = TH_HEADER_LENGTH;
1776 ch->ccw[9].cda = virt_to_phys(ch->rcvd_xid_th);
1778 ch->ccw[10].cmd_code = CCW_CMD_READ;
1779 ch->ccw[10].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1780 ch->ccw[10].count = XID2_LENGTH;
1781 ch->ccw[10].cda = virt_to_phys(ch->rcvd_xid);
1783 if (ch->xid_th == NULL)
1785 ch->ccw[11].cmd_code = CCW_CMD_WRITE;
1786 ch->ccw[11].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1787 ch->ccw[11].count = TH_HEADER_LENGTH;
1788 ch->ccw[11].cda = virt_to_phys(ch->xid_th);
1790 if (ch->xid == NULL)
1792 ch->ccw[12].cmd_code = CCW_CMD_WRITE;
1793 ch->ccw[12].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1794 ch->ccw[12].count = XID2_LENGTH;
1795 ch->ccw[12].cda = virt_to_phys(ch->xid);
1797 if (ch->xid_id == NULL)
1799 ch->ccw[13].cmd_code = CCW_CMD_WRITE;
1800 ch->ccw[13].cda = virt_to_phys(ch->xid_id);
1803 ch->ccw[13].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1804 ch->ccw[13].count = 4;
1806 ch->ccw[14].cmd_code = CCW_CMD_NOOP;
1807 ch->ccw[14].flags = CCW_FLAG_SLI;
1808 ch->ccw[14].count = 0;
1809 ch->ccw[14].cda = 0;
1811 CTCM_CCW_DUMP((char *)&ch->ccw[8], sizeof(struct ccw1) * 7);
1812 CTCM_D3_DUMP((char *)ch->xid_th, TH_HEADER_LENGTH);
1813 CTCM_D3_DUMP((char *)ch->xid, XID2_LENGTH);
1814 CTCM_D3_DUMP((char *)ch->xid_id, 4);
1817 /* Such conditional locking is a known problem for
1818 * sparse because its static undeterministic.
1819 * Warnings should be ignored here. */
1820 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1824 fsm_addtimer(&ch->timer, 5000 , CTC_EVENT_TIMER, ch);
1825 rc = ccw_device_start(ch->cdev, &ch->ccw[8],
1826 (unsigned long)ch, 0xff, 0);
1828 if (gotlock) /* see remark above about conditional locking */
1829 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1832 ctcm_ccw_check_rc(ch, rc,
1833 (side == XSIDE) ? "x-side XID" : "y-side XID");
1837 CTCM_PR_DEBUG("Exit %s: ch=0x%p id=%s\n",
1838 __func__, ch, ch->id);
1844 * MPC Group Station FSM action
1845 * CTCM_PROTO_MPC only
1847 static void mpc_action_xside_xid(fsm_instance *fsm, int event, void *arg)
1849 mpc_action_side_xid(fsm, arg, XSIDE);
1853 * MPC Group Station FSM action
1854 * CTCM_PROTO_MPC only
1856 static void mpc_action_yside_xid(fsm_instance *fsm, int event, void *arg)
1858 mpc_action_side_xid(fsm, arg, YSIDE);
1862 * MPC Group Station FSM action
1863 * CTCM_PROTO_MPC only
1865 static void mpc_action_doxid0(fsm_instance *fsm, int event, void *arg)
1867 struct channel *ch = arg;
1868 struct net_device *dev = ch->netdev;
1869 struct ctcm_priv *priv = dev->ml_priv;
1870 struct mpc_group *grp = priv->mpcg;
1872 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1873 __func__, smp_processor_id(), ch, ch->id);
1875 if (ch->xid == NULL) {
1876 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1877 "%s(%s): ch->xid == NULL",
1878 CTCM_FUNTAIL, dev->name);
1882 fsm_newstate(ch->fsm, CH_XID0_INPROGRESS);
1884 ch->xid->xid2_option = XID2_0;
1886 switch (fsm_getstate(grp->fsm)) {
1887 case MPCG_STATE_XID2INITW:
1888 case MPCG_STATE_XID2INITX:
1889 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1891 case MPCG_STATE_XID0IOWAIT:
1892 case MPCG_STATE_XID0IOWAIX:
1893 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1897 fsm_event(grp->fsm, MPCG_EVENT_DOIO, ch);
1903 * MPC Group Station FSM action
1904 * CTCM_PROTO_MPC only
1906 static void mpc_action_doxid7(fsm_instance *fsm, int event, void *arg)
1908 struct net_device *dev = arg;
1909 struct ctcm_priv *priv = dev->ml_priv;
1910 struct mpc_group *grp = NULL;
1917 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1921 for (direction = READ; direction <= WRITE; direction++) {
1922 struct channel *ch = priv->channel[direction];
1923 struct xid2 *thisxid = ch->xid;
1924 ch->xid_skb->data = ch->xid_skb_data;
1925 skb_reset_tail_pointer(ch->xid_skb);
1926 ch->xid_skb->len = 0;
1927 thisxid->xid2_option = XID2_7;
1931 if (grp->outstanding_xid7_p2 > 0) {
1932 if (grp->roll == YSIDE) {
1933 if (fsm_getstate(ch->fsm) == CH_XID7_PENDING1) {
1934 fsm_newstate(ch->fsm, CH_XID7_PENDING2);
1935 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1936 memcpy(skb_put(ch->xid_skb,
1938 &thdummy, TH_HEADER_LENGTH);
1941 } else if (fsm_getstate(ch->fsm) < CH_XID7_PENDING2) {
1942 fsm_newstate(ch->fsm, CH_XID7_PENDING2);
1943 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1944 memcpy(skb_put(ch->xid_skb,
1946 &thnorm, TH_HEADER_LENGTH);
1951 if (grp->roll == YSIDE) {
1952 if (fsm_getstate(ch->fsm) < CH_XID7_PENDING4) {
1953 fsm_newstate(ch->fsm, CH_XID7_PENDING4);
1954 memcpy(skb_put(ch->xid_skb,
1956 &thnorm, TH_HEADER_LENGTH);
1957 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1960 } else if (fsm_getstate(ch->fsm) == CH_XID7_PENDING3) {
1961 fsm_newstate(ch->fsm, CH_XID7_PENDING4);
1962 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1963 memcpy(skb_put(ch->xid_skb, TH_HEADER_LENGTH),
1964 &thdummy, TH_HEADER_LENGTH);
1970 fsm_event(grp->fsm, MPCG_EVENT_DOIO, ch);
1977 * MPC Group Station FSM action
1978 * CTCM_PROTO_MPC only
1980 static void mpc_action_rcvd_xid0(fsm_instance *fsm, int event, void *arg)
1983 struct mpcg_info *mpcginfo = arg;
1984 struct channel *ch = mpcginfo->ch;
1985 struct net_device *dev = ch->netdev;
1986 struct ctcm_priv *priv = dev->ml_priv;
1987 struct mpc_group *grp = priv->mpcg;
1989 CTCM_PR_DEBUG("%s: ch-id:%s xid2:%i xid7:%i xidt_p2:%i \n",
1990 __func__, ch->id, grp->outstanding_xid2,
1991 grp->outstanding_xid7, grp->outstanding_xid7_p2);
1993 if (fsm_getstate(ch->fsm) < CH_XID7_PENDING)
1994 fsm_newstate(ch->fsm, CH_XID7_PENDING);
1996 grp->outstanding_xid2--;
1997 grp->outstanding_xid7++;
1998 grp->outstanding_xid7_p2++;
2000 /* must change state before validating xid to */
2001 /* properly handle interim interrupts received*/
2002 switch (fsm_getstate(grp->fsm)) {
2003 case MPCG_STATE_XID2INITW:
2004 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITX);
2005 mpc_validate_xid(mpcginfo);
2007 case MPCG_STATE_XID0IOWAIT:
2008 fsm_newstate(grp->fsm, MPCG_STATE_XID0IOWAIX);
2009 mpc_validate_xid(mpcginfo);
2011 case MPCG_STATE_XID2INITX:
2012 if (grp->outstanding_xid2 == 0) {
2013 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITW);
2014 mpc_validate_xid(mpcginfo);
2015 fsm_event(grp->fsm, MPCG_EVENT_XID2DONE, dev);
2018 case MPCG_STATE_XID0IOWAIX:
2019 if (grp->outstanding_xid2 == 0) {
2020 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITI);
2021 mpc_validate_xid(mpcginfo);
2022 fsm_event(grp->fsm, MPCG_EVENT_XID2DONE, dev);
2028 CTCM_PR_DEBUG("ctcmpc:%s() %s xid2:%i xid7:%i xidt_p2:%i \n",
2029 __func__, ch->id, grp->outstanding_xid2,
2030 grp->outstanding_xid7, grp->outstanding_xid7_p2);
2031 CTCM_PR_DEBUG("ctcmpc:%s() %s grpstate: %s chanstate: %s \n",
2033 fsm_getstate_str(grp->fsm), fsm_getstate_str(ch->fsm));
2040 * MPC Group Station FSM action
2041 * CTCM_PROTO_MPC only
2043 static void mpc_action_rcvd_xid7(fsm_instance *fsm, int event, void *arg)
2045 struct mpcg_info *mpcginfo = arg;
2046 struct channel *ch = mpcginfo->ch;
2047 struct net_device *dev = ch->netdev;
2048 struct ctcm_priv *priv = dev->ml_priv;
2049 struct mpc_group *grp = priv->mpcg;
2051 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
2052 __func__, smp_processor_id(), ch, ch->id);
2053 CTCM_PR_DEBUG("%s: outstanding_xid7: %i, outstanding_xid7_p2: %i\n",
2054 __func__, grp->outstanding_xid7, grp->outstanding_xid7_p2);
2056 grp->outstanding_xid7--;
2057 ch->xid_skb->data = ch->xid_skb_data;
2058 skb_reset_tail_pointer(ch->xid_skb);
2059 ch->xid_skb->len = 0;
2061 switch (fsm_getstate(grp->fsm)) {
2062 case MPCG_STATE_XID7INITI:
2063 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITZ);
2064 mpc_validate_xid(mpcginfo);
2066 case MPCG_STATE_XID7INITW:
2067 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITX);
2068 mpc_validate_xid(mpcginfo);
2070 case MPCG_STATE_XID7INITZ:
2071 case MPCG_STATE_XID7INITX:
2072 if (grp->outstanding_xid7 == 0) {
2073 if (grp->outstanding_xid7_p2 > 0) {
2074 grp->outstanding_xid7 =
2075 grp->outstanding_xid7_p2;
2076 grp->outstanding_xid7_p2 = 0;
2078 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITF);
2080 mpc_validate_xid(mpcginfo);
2081 fsm_event(grp->fsm, MPCG_EVENT_XID7DONE, dev);
2084 mpc_validate_xid(mpcginfo);
2092 * mpc_action helper of an MPC Group Station FSM action
2093 * CTCM_PROTO_MPC only
2095 static int mpc_send_qllc_discontact(struct net_device *dev)
2098 struct sk_buff *skb;
2099 struct qllc *qllcptr;
2100 struct ctcm_priv *priv = dev->ml_priv;
2101 struct mpc_group *grp = priv->mpcg;
2103 CTCM_PR_DEBUG("%s: GROUP STATE: %s\n",
2104 __func__, mpcg_state_names[grp->saved_state]);
2106 switch (grp->saved_state) {
2108 * establish conn callback function is
2109 * preferred method to report failure
2111 case MPCG_STATE_XID0IOWAIT:
2112 case MPCG_STATE_XID0IOWAIX:
2113 case MPCG_STATE_XID7INITI:
2114 case MPCG_STATE_XID7INITZ:
2115 case MPCG_STATE_XID2INITW:
2116 case MPCG_STATE_XID2INITX:
2117 case MPCG_STATE_XID7INITW:
2118 case MPCG_STATE_XID7INITX:
2119 if (grp->estconnfunc) {
2120 grp->estconnfunc(grp->port_num, -1, 0);
2121 grp->estconnfunc = NULL;
2124 case MPCG_STATE_FLOWC:
2125 case MPCG_STATE_READY:
2126 grp->send_qllc_disc = 2;
2127 new_len = sizeof(struct qllc);
2128 qllcptr = kzalloc(new_len, gfp_type() | GFP_DMA);
2129 if (qllcptr == NULL) {
2130 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2131 "%s(%s): qllcptr allocation error",
2132 CTCM_FUNTAIL, dev->name);
2136 qllcptr->qllc_address = 0xcc;
2137 qllcptr->qllc_commands = 0x03;
2139 skb = __dev_alloc_skb(new_len, GFP_ATOMIC);
2142 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2143 "%s(%s): skb allocation error",
2144 CTCM_FUNTAIL, dev->name);
2145 priv->stats.rx_dropped++;
2150 memcpy(skb_put(skb, new_len), qllcptr, new_len);
2153 if (skb_headroom(skb) < 4) {
2154 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2155 "%s(%s): skb_headroom error",
2156 CTCM_FUNTAIL, dev->name);
2157 dev_kfree_skb_any(skb);
2161 *((__u32 *)skb_push(skb, 4)) = priv->channel[READ]->pdu_seq;
2162 priv->channel[READ]->pdu_seq++;
2163 CTCM_PR_DBGDATA("ctcmpc: %s ToDCM_pdu_seq= %08x\n",
2164 __func__, priv->channel[READ]->pdu_seq);
2166 /* receipt of CC03 resets anticipated sequence number on
2168 priv->channel[READ]->pdu_seq = 0x00;
2169 skb_reset_mac_header(skb);
2171 skb->protocol = htons(ETH_P_SNAP);
2172 skb->ip_summed = CHECKSUM_UNNECESSARY;
2174 CTCM_D3_DUMP(skb->data, (sizeof(struct qllc) + 4));
2185 /* --- This is the END my friend --- */