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 #define KMSG_COMPONENT "ctcm"
23 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
29 #include <linux/errno.h>
30 #include <linux/types.h>
31 #include <linux/interrupt.h>
32 #include <linux/timer.h>
33 #include <linux/sched.h>
35 #include <linux/signal.h>
36 #include <linux/string.h>
37 #include <linux/proc_fs.h>
40 #include <linux/if_arp.h>
41 #include <linux/tcp.h>
42 #include <linux/skbuff.h>
43 #include <linux/ctype.h>
44 #include <linux/netdevice.h>
47 #include <linux/io.h> /* instead of <asm/io.h> ok ? */
48 #include <asm/ccwdev.h>
49 #include <asm/ccwgroup.h>
50 #include <linux/bitops.h> /* instead of <asm/bitops.h> ok ? */
51 #include <linux/uaccess.h> /* instead of <asm/uaccess.h> ok ? */
52 #include <linux/wait.h>
53 #include <linux/moduleparam.h>
54 #include <asm/idals.h>
58 #include "ctcm_main.h"
59 #include "ctcm_fsms.h"
61 static const struct xid2 init_xid = {
62 .xid2_type_id = XID_FM2,
74 .xid2_option = XID2_0,
77 .xid2_dlc_type = XID2_READ_SIDE,
81 .xid2_buf_len = (MPC_BUFSIZE_DEFAULT - 35),
84 static const struct th_header thnorm = {
86 .th_ch_flag = TH_IS_XID,
87 .th_blk_flag = TH_DATA_IS_XID,
89 .th_seq_num = 0x00000000,
92 static const struct th_header thdummy = {
95 .th_blk_flag = TH_DATA_IS_XID,
97 .th_seq_num = 0x00000000,
101 * Definition of one MPC group
105 * Compatibility macros for busy handling
106 * of network devices.
109 static void ctcmpc_unpack_skb(struct channel *ch, struct sk_buff *pskb);
112 * MPC Group state machine actions (static prototypes)
114 static void mpc_action_nop(fsm_instance *fsm, int event, void *arg);
115 static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg);
116 static void mpc_action_go_inop(fsm_instance *fi, int event, void *arg);
117 static void mpc_action_timeout(fsm_instance *fi, int event, void *arg);
118 static int mpc_validate_xid(struct mpcg_info *mpcginfo);
119 static void mpc_action_yside_xid(fsm_instance *fsm, int event, void *arg);
120 static void mpc_action_doxid0(fsm_instance *fsm, int event, void *arg);
121 static void mpc_action_doxid7(fsm_instance *fsm, int event, void *arg);
122 static void mpc_action_xside_xid(fsm_instance *fsm, int event, void *arg);
123 static void mpc_action_rcvd_xid0(fsm_instance *fsm, int event, void *arg);
124 static void mpc_action_rcvd_xid7(fsm_instance *fsm, int event, void *arg);
127 /*-------------------------------------------------------------------*
128 * Dump buffer format *
130 *--------------------------------------------------------------------*/
131 void ctcmpc_dumpit(char *buf, int len)
133 __u32 ct, sw, rm, dup;
135 char tbuf[82], tdup[82];
136 #if (UTS_MACHINE == s390x)
142 char bhex[82], duphex[82];
151 for (ct = 0; ct < len; ct++, ptr++, rptr++) {
153 #if (UTS_MACHINE == s390x)
154 sprintf(addr, "%16.16lx", (__u64)rptr);
156 sprintf(addr, "%8.8X", (__u32)rptr);
159 sprintf(boff, "%4.4X", (__u32)ct);
163 if ((sw == 4) || (sw == 12))
168 #if (UTS_MACHINE == s390x)
169 sprintf(tbuf, "%2.2lX", (__u64)*ptr);
171 sprintf(tbuf, "%2.2X", (__u32)*ptr);
176 if ((0 != isprint(*ptr)) && (*ptr >= 0x20))
186 if ((strcmp(duphex, bhex)) != 0) {
189 "Duplicate as above to %s", addr);
190 ctcm_pr_debug(" --- %s ---\n",
193 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
194 addr, boff, bhex, basc);
196 strcpy(duphex, bhex);
205 for ( ; rm > 0; rm--, sw++) {
206 if ((sw == 4) || (sw == 12))
214 sprintf(tdup, "Duplicate as above to %s", addr);
215 ctcm_pr_debug(" --- %s ---\n", tdup);
217 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
218 addr, boff, bhex, basc);
221 sprintf(tdup, "Duplicate as above to %s", addr);
222 ctcm_pr_debug(" --- %s ---\n", tdup);
225 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
226 addr, boff, bhex, basc);
232 } /* end of ctcmpc_dumpit */
237 * Dump header and first 16 bytes of an sk_buff for debugging purposes.
239 * skb The sk_buff to dump.
240 * offset Offset relative to skb-data, where to start the dump.
242 void ctcmpc_dump_skb(struct sk_buff *skb, int offset)
245 struct th_header *header;
254 header = (struct th_header *)p;
256 ctcm_pr_debug("dump:\n");
257 ctcm_pr_debug("skb len=%d \n", skb->len);
259 switch (header->th_ch_flag) {
264 if ((header->th_blk_flag == TH_DATA_IS_XID) &&
265 (header->th_is_xid == 0x01))
275 pheader = (struct pdu *)p;
276 ctcm_pr_debug("pdu->offset: %d hex: %04x\n",
277 pheader->pdu_offset, pheader->pdu_offset);
278 ctcm_pr_debug("pdu->flag : %02x\n", pheader->pdu_flag);
279 ctcm_pr_debug("pdu->proto : %02x\n", pheader->pdu_proto);
280 ctcm_pr_debug("pdu->seq : %02x\n", pheader->pdu_seq);
284 ctcm_pr_debug("th->seg : %02x\n", header->th_seg);
285 ctcm_pr_debug("th->ch : %02x\n", header->th_ch_flag);
286 ctcm_pr_debug("th->blk_flag: %02x\n", header->th_blk_flag);
287 ctcm_pr_debug("th->type : %s\n",
288 (header->th_is_xid) ? "DATA" : "XID");
289 ctcm_pr_debug("th->seqnum : %04x\n", header->th_seq_num);
295 ctcm_pr_debug("data: ");
296 for (i = 0; i < bl; i++)
297 ctcm_pr_debug("%02x%s", *p++, (i % 16) ? " " : "\n");
302 static struct net_device *ctcmpc_get_dev(int port_num)
305 struct net_device *dev;
306 struct ctcm_priv *priv;
308 sprintf(device, "%s%i", MPC_DEVICE_NAME, port_num);
310 dev = __dev_get_by_name(&init_net, device);
313 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
314 "%s: Device not found by name: %s",
315 CTCM_FUNTAIL, device);
320 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
321 "%s(%s): dev->ml_priv is NULL",
322 CTCM_FUNTAIL, device);
325 if (priv->mpcg == NULL) {
326 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
327 "%s(%s): priv->mpcg is NULL",
328 CTCM_FUNTAIL, device);
335 * ctc_mpc_alloc_channel
336 * (exported interface)
338 * Device Initialization :
339 * ACTPATH driven IO operations
341 int ctc_mpc_alloc_channel(int port_num, void (*callback)(int, int))
343 struct net_device *dev;
344 struct mpc_group *grp;
345 struct ctcm_priv *priv;
347 dev = ctcmpc_get_dev(port_num);
353 grp->allochanfunc = callback;
354 grp->port_num = port_num;
355 grp->port_persist = 1;
357 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
359 CTCM_FUNTAIL, dev->name, fsm_getstate_str(grp->fsm));
361 switch (fsm_getstate(grp->fsm)) {
362 case MPCG_STATE_INOP:
363 /* Group is in the process of terminating */
364 grp->alloc_called = 1;
366 case MPCG_STATE_RESET:
367 /* MPC Group will transition to state */
368 /* MPCG_STATE_XID2INITW iff the minimum number */
369 /* of 1 read and 1 write channel have successfully*/
371 /*fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);*/
373 grp->send_qllc_disc = 1;
374 case MPCG_STATE_XID0IOWAIT:
375 fsm_deltimer(&grp->timer);
376 grp->outstanding_xid2 = 0;
377 grp->outstanding_xid7 = 0;
378 grp->outstanding_xid7_p2 = 0;
379 grp->saved_xid2 = NULL;
382 fsm_event(priv->fsm, DEV_EVENT_START, dev);
384 case MPCG_STATE_READY:
385 /* XID exchanges completed after PORT was activated */
386 /* Link station already active */
387 /* Maybe timing issue...retry callback */
388 grp->allocchan_callback_retries++;
389 if (grp->allocchan_callback_retries < 4) {
390 if (grp->allochanfunc)
391 grp->allochanfunc(grp->port_num,
392 grp->group_max_buflen);
394 /* there are problems...bail out */
395 /* there may be a state mismatch so restart */
396 grp->port_persist = 1;
397 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
398 grp->allocchan_callback_retries = 0;
405 EXPORT_SYMBOL(ctc_mpc_alloc_channel);
408 * ctc_mpc_establish_connectivity
409 * (exported interface)
411 void ctc_mpc_establish_connectivity(int port_num,
412 void (*callback)(int, int, int))
414 struct net_device *dev;
415 struct mpc_group *grp;
416 struct ctcm_priv *priv;
417 struct channel *rch, *wch;
419 dev = ctcmpc_get_dev(port_num);
424 rch = priv->channel[READ];
425 wch = priv->channel[WRITE];
427 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
429 CTCM_FUNTAIL, dev->name, fsm_getstate_str(grp->fsm));
431 grp->estconnfunc = callback;
432 grp->port_num = port_num;
434 switch (fsm_getstate(grp->fsm)) {
435 case MPCG_STATE_READY:
436 /* XID exchanges completed after PORT was activated */
437 /* Link station already active */
438 /* Maybe timing issue...retry callback */
439 fsm_deltimer(&grp->timer);
440 grp->estconn_callback_retries++;
441 if (grp->estconn_callback_retries < 4) {
442 if (grp->estconnfunc) {
443 grp->estconnfunc(grp->port_num, 0,
444 grp->group_max_buflen);
445 grp->estconnfunc = NULL;
448 /* there are problems...bail out */
449 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
450 grp->estconn_callback_retries = 0;
453 case MPCG_STATE_INOP:
454 case MPCG_STATE_RESET:
455 /* MPC Group is not ready to start XID - min num of */
456 /* 1 read and 1 write channel have not been acquired*/
458 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
459 "%s(%s): REJECTED - inactive channels",
460 CTCM_FUNTAIL, dev->name);
461 if (grp->estconnfunc) {
462 grp->estconnfunc(grp->port_num, -1, 0);
463 grp->estconnfunc = NULL;
466 case MPCG_STATE_XID2INITW:
467 /* alloc channel was called but no XID exchange */
468 /* has occurred. initiate xside XID exchange */
469 /* make sure yside XID0 processing has not started */
471 if ((fsm_getstate(rch->fsm) > CH_XID0_PENDING) ||
472 (fsm_getstate(wch->fsm) > CH_XID0_PENDING)) {
473 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
474 "%s(%s): ABORT - PASSIVE XID",
475 CTCM_FUNTAIL, dev->name);
478 grp->send_qllc_disc = 1;
479 fsm_newstate(grp->fsm, MPCG_STATE_XID0IOWAIT);
480 fsm_deltimer(&grp->timer);
481 fsm_addtimer(&grp->timer, MPC_XID_TIMEOUT_VALUE,
482 MPCG_EVENT_TIMER, dev);
483 grp->outstanding_xid7 = 0;
484 grp->outstanding_xid7_p2 = 0;
485 grp->saved_xid2 = NULL;
486 if ((rch->in_mpcgroup) &&
487 (fsm_getstate(rch->fsm) == CH_XID0_PENDING))
488 fsm_event(grp->fsm, MPCG_EVENT_XID0DO, rch);
490 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
491 "%s(%s): RX-%s not ready for ACTIVE XID0",
492 CTCM_FUNTAIL, dev->name, rch->id);
493 if (grp->estconnfunc) {
494 grp->estconnfunc(grp->port_num, -1, 0);
495 grp->estconnfunc = NULL;
497 fsm_deltimer(&grp->timer);
500 if ((wch->in_mpcgroup) &&
501 (fsm_getstate(wch->fsm) == CH_XID0_PENDING))
502 fsm_event(grp->fsm, MPCG_EVENT_XID0DO, wch);
504 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
505 "%s(%s): WX-%s not ready for ACTIVE XID0",
506 CTCM_FUNTAIL, dev->name, wch->id);
507 if (grp->estconnfunc) {
508 grp->estconnfunc(grp->port_num, -1, 0);
509 grp->estconnfunc = NULL;
511 fsm_deltimer(&grp->timer);
515 case MPCG_STATE_XID0IOWAIT:
516 /* already in active XID negotiations */
522 CTCM_PR_DEBUG("Exit %s()\n", __func__);
525 EXPORT_SYMBOL(ctc_mpc_establish_connectivity);
529 * (exported interface)
531 void ctc_mpc_dealloc_ch(int port_num)
533 struct net_device *dev;
534 struct ctcm_priv *priv;
535 struct mpc_group *grp;
537 dev = ctcmpc_get_dev(port_num);
543 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_DEBUG,
544 "%s: %s: refcount = %d\n",
545 CTCM_FUNTAIL, dev->name, atomic_read(&dev->refcnt));
547 fsm_deltimer(&priv->restart_timer);
548 grp->channels_terminating = 0;
549 fsm_deltimer(&grp->timer);
550 grp->allochanfunc = NULL;
551 grp->estconnfunc = NULL;
552 grp->port_persist = 0;
553 grp->send_qllc_disc = 0;
554 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
559 EXPORT_SYMBOL(ctc_mpc_dealloc_ch);
562 * ctc_mpc_flow_control
563 * (exported interface)
565 void ctc_mpc_flow_control(int port_num, int flowc)
567 struct ctcm_priv *priv;
568 struct mpc_group *grp;
569 struct net_device *dev;
573 dev = ctcmpc_get_dev(port_num);
579 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
580 "%s: %s: flowc = %d",
581 CTCM_FUNTAIL, dev->name, flowc);
583 rch = priv->channel[READ];
585 mpcg_state = fsm_getstate(grp->fsm);
588 if (mpcg_state == MPCG_STATE_FLOWC)
590 if (mpcg_state == MPCG_STATE_READY) {
591 if (grp->flow_off_called == 1)
592 grp->flow_off_called = 0;
594 fsm_newstate(grp->fsm, MPCG_STATE_FLOWC);
599 if (mpcg_state == MPCG_STATE_FLOWC) {
600 fsm_newstate(grp->fsm, MPCG_STATE_READY);
601 /* ensure any data that has accumulated */
602 /* on the io_queue will now be sen t */
603 tasklet_schedule(&rch->ch_tasklet);
605 /* possible race condition */
606 if (mpcg_state == MPCG_STATE_READY) {
607 grp->flow_off_called = 1;
614 EXPORT_SYMBOL(ctc_mpc_flow_control);
616 static int mpc_send_qllc_discontact(struct net_device *);
619 * helper function of ctcmpc_unpack_skb
621 static void mpc_rcvd_sweep_resp(struct mpcg_info *mpcginfo)
623 struct channel *rch = mpcginfo->ch;
624 struct net_device *dev = rch->netdev;
625 struct ctcm_priv *priv = dev->ml_priv;
626 struct mpc_group *grp = priv->mpcg;
627 struct channel *ch = priv->channel[WRITE];
629 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, ch, ch->id);
630 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
632 grp->sweep_rsp_pend_num--;
634 if ((grp->sweep_req_pend_num == 0) &&
635 (grp->sweep_rsp_pend_num == 0)) {
636 fsm_deltimer(&ch->sweep_timer);
638 rch->th_seq_num = 0x00;
639 ch->th_seq_num = 0x00;
640 ctcm_clear_busy_do(dev);
650 * helper function of mpc_rcvd_sweep_req
651 * which is a helper of ctcmpc_unpack_skb
653 static void ctcmpc_send_sweep_resp(struct channel *rch)
655 struct net_device *dev = rch->netdev;
656 struct ctcm_priv *priv = dev->ml_priv;
657 struct mpc_group *grp = priv->mpcg;
659 struct th_sweep *header;
660 struct sk_buff *sweep_skb;
661 struct channel *ch = priv->channel[WRITE];
663 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, rch, rch->id);
665 sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC | GFP_DMA);
666 if (sweep_skb == NULL) {
667 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
668 "%s(%s): sweep_skb allocation ERROR\n",
669 CTCM_FUNTAIL, rch->id);
674 header = (struct th_sweep *)
675 kmalloc(sizeof(struct th_sweep), gfp_type());
678 dev_kfree_skb_any(sweep_skb);
683 header->th.th_seg = 0x00 ;
684 header->th.th_ch_flag = TH_SWEEP_RESP;
685 header->th.th_blk_flag = 0x00;
686 header->th.th_is_xid = 0x00;
687 header->th.th_seq_num = 0x00;
688 header->sw.th_last_seq = ch->th_seq_num;
690 memcpy(skb_put(sweep_skb, TH_SWEEP_LENGTH), header, TH_SWEEP_LENGTH);
694 dev->trans_start = jiffies;
695 skb_queue_tail(&ch->sweep_queue, sweep_skb);
697 fsm_addtimer(&ch->sweep_timer, 100, CTC_EVENT_RSWEEP_TIMER, ch);
704 ctcm_clear_busy_do(dev);
705 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
712 * helper function of ctcmpc_unpack_skb
714 static void mpc_rcvd_sweep_req(struct mpcg_info *mpcginfo)
716 struct channel *rch = mpcginfo->ch;
717 struct net_device *dev = rch->netdev;
718 struct ctcm_priv *priv = dev->ml_priv;
719 struct mpc_group *grp = priv->mpcg;
720 struct channel *ch = priv->channel[WRITE];
723 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
724 " %s(): ch=0x%p id=%s\n", __func__, ch, ch->id);
726 if (grp->in_sweep == 0) {
728 ctcm_test_and_set_busy(dev);
729 grp->sweep_req_pend_num = grp->active_channels[READ];
730 grp->sweep_rsp_pend_num = grp->active_channels[READ];
733 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
735 grp->sweep_req_pend_num--;
736 ctcmpc_send_sweep_resp(ch);
742 * MPC Group Station FSM definitions
744 static const char *mpcg_event_names[] = {
745 [MPCG_EVENT_INOP] = "INOP Condition",
746 [MPCG_EVENT_DISCONC] = "Discontact Received",
747 [MPCG_EVENT_XID0DO] = "Channel Active - Start XID",
748 [MPCG_EVENT_XID2] = "XID2 Received",
749 [MPCG_EVENT_XID2DONE] = "XID0 Complete",
750 [MPCG_EVENT_XID7DONE] = "XID7 Complete",
751 [MPCG_EVENT_TIMER] = "XID Setup Timer",
752 [MPCG_EVENT_DOIO] = "XID DoIO",
755 static const char *mpcg_state_names[] = {
756 [MPCG_STATE_RESET] = "Reset",
757 [MPCG_STATE_INOP] = "INOP",
758 [MPCG_STATE_XID2INITW] = "Passive XID- XID0 Pending Start",
759 [MPCG_STATE_XID2INITX] = "Passive XID- XID0 Pending Complete",
760 [MPCG_STATE_XID7INITW] = "Passive XID- XID7 Pending P1 Start",
761 [MPCG_STATE_XID7INITX] = "Passive XID- XID7 Pending P2 Complete",
762 [MPCG_STATE_XID0IOWAIT] = "Active XID- XID0 Pending Start",
763 [MPCG_STATE_XID0IOWAIX] = "Active XID- XID0 Pending Complete",
764 [MPCG_STATE_XID7INITI] = "Active XID- XID7 Pending Start",
765 [MPCG_STATE_XID7INITZ] = "Active XID- XID7 Pending Complete ",
766 [MPCG_STATE_XID7INITF] = "XID - XID7 Complete ",
767 [MPCG_STATE_FLOWC] = "FLOW CONTROL ON",
768 [MPCG_STATE_READY] = "READY",
772 * The MPC Group Station FSM
775 static const fsm_node mpcg_fsm[] = {
776 { MPCG_STATE_RESET, MPCG_EVENT_INOP, mpc_action_go_inop },
777 { MPCG_STATE_INOP, MPCG_EVENT_INOP, mpc_action_nop },
778 { MPCG_STATE_FLOWC, MPCG_EVENT_INOP, mpc_action_go_inop },
780 { MPCG_STATE_READY, MPCG_EVENT_DISCONC, mpc_action_discontact },
781 { MPCG_STATE_READY, MPCG_EVENT_INOP, mpc_action_go_inop },
783 { MPCG_STATE_XID2INITW, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
784 { MPCG_STATE_XID2INITW, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
785 { MPCG_STATE_XID2INITW, MPCG_EVENT_INOP, mpc_action_go_inop },
786 { MPCG_STATE_XID2INITW, MPCG_EVENT_TIMER, mpc_action_timeout },
787 { MPCG_STATE_XID2INITW, MPCG_EVENT_DOIO, mpc_action_yside_xid },
789 { MPCG_STATE_XID2INITX, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
790 { MPCG_STATE_XID2INITX, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
791 { MPCG_STATE_XID2INITX, MPCG_EVENT_INOP, mpc_action_go_inop },
792 { MPCG_STATE_XID2INITX, MPCG_EVENT_TIMER, mpc_action_timeout },
793 { MPCG_STATE_XID2INITX, MPCG_EVENT_DOIO, mpc_action_yside_xid },
795 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID2DONE, mpc_action_doxid7 },
796 { MPCG_STATE_XID7INITW, MPCG_EVENT_DISCONC, mpc_action_discontact },
797 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
798 { MPCG_STATE_XID7INITW, MPCG_EVENT_INOP, mpc_action_go_inop },
799 { MPCG_STATE_XID7INITW, MPCG_EVENT_TIMER, mpc_action_timeout },
800 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
801 { MPCG_STATE_XID7INITW, MPCG_EVENT_DOIO, mpc_action_yside_xid },
803 { MPCG_STATE_XID7INITX, MPCG_EVENT_DISCONC, mpc_action_discontact },
804 { MPCG_STATE_XID7INITX, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
805 { MPCG_STATE_XID7INITX, MPCG_EVENT_INOP, mpc_action_go_inop },
806 { MPCG_STATE_XID7INITX, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
807 { MPCG_STATE_XID7INITX, MPCG_EVENT_TIMER, mpc_action_timeout },
808 { MPCG_STATE_XID7INITX, MPCG_EVENT_DOIO, mpc_action_yside_xid },
810 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
811 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_DISCONC, mpc_action_discontact },
812 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
813 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_INOP, mpc_action_go_inop },
814 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_TIMER, mpc_action_timeout },
815 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_DOIO, mpc_action_xside_xid },
817 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
818 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_DISCONC, mpc_action_discontact },
819 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
820 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_INOP, mpc_action_go_inop },
821 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_TIMER, mpc_action_timeout },
822 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_DOIO, mpc_action_xside_xid },
824 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID2DONE, mpc_action_doxid7 },
825 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
826 { MPCG_STATE_XID7INITI, MPCG_EVENT_DISCONC, mpc_action_discontact },
827 { MPCG_STATE_XID7INITI, MPCG_EVENT_INOP, mpc_action_go_inop },
828 { MPCG_STATE_XID7INITI, MPCG_EVENT_TIMER, mpc_action_timeout },
829 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
830 { MPCG_STATE_XID7INITI, MPCG_EVENT_DOIO, mpc_action_xside_xid },
832 { MPCG_STATE_XID7INITZ, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
833 { MPCG_STATE_XID7INITZ, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
834 { MPCG_STATE_XID7INITZ, MPCG_EVENT_DISCONC, mpc_action_discontact },
835 { MPCG_STATE_XID7INITZ, MPCG_EVENT_INOP, mpc_action_go_inop },
836 { MPCG_STATE_XID7INITZ, MPCG_EVENT_TIMER, mpc_action_timeout },
837 { MPCG_STATE_XID7INITZ, MPCG_EVENT_DOIO, mpc_action_xside_xid },
839 { MPCG_STATE_XID7INITF, MPCG_EVENT_INOP, mpc_action_go_inop },
840 { MPCG_STATE_XID7INITF, MPCG_EVENT_XID7DONE, mpc_action_go_ready },
843 static int mpcg_fsm_len = ARRAY_SIZE(mpcg_fsm);
846 * MPC Group Station FSM action
847 * CTCM_PROTO_MPC only
849 static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg)
851 struct net_device *dev = arg;
852 struct ctcm_priv *priv = dev->ml_priv;
853 struct mpc_group *grp = priv->mpcg;
856 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
857 "%s(%s): No MPC group",
858 CTCM_FUNTAIL, dev->name);
862 fsm_deltimer(&grp->timer);
864 if (grp->saved_xid2->xid2_flag2 == 0x40) {
865 priv->xid->xid2_flag2 = 0x00;
866 if (grp->estconnfunc) {
867 grp->estconnfunc(grp->port_num, 1,
868 grp->group_max_buflen);
869 grp->estconnfunc = NULL;
870 } else if (grp->allochanfunc)
871 grp->send_qllc_disc = 1;
873 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
874 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
876 CTCM_FUNTAIL, dev->name);
880 grp->port_persist = 1;
881 grp->out_of_sequence = 0;
882 grp->estconn_called = 0;
884 tasklet_hi_schedule(&grp->mpc_tasklet2);
890 * helper of ctcm_init_netdevice
891 * CTCM_PROTO_MPC only
893 void mpc_group_ready(unsigned long adev)
895 struct net_device *dev = (struct net_device *)adev;
896 struct ctcm_priv *priv = dev->ml_priv;
897 struct mpc_group *grp = priv->mpcg;
898 struct channel *ch = NULL;
901 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
902 "%s(%s): No MPC group",
903 CTCM_FUNTAIL, dev->name);
907 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
908 "%s: %s: GROUP TRANSITIONED TO READY, maxbuf = %d\n",
909 CTCM_FUNTAIL, dev->name, grp->group_max_buflen);
911 fsm_newstate(grp->fsm, MPCG_STATE_READY);
913 /* Put up a read on the channel */
914 ch = priv->channel[READ];
916 CTCM_PR_DBGDATA("ctcmpc: %s() ToDCM_pdu_seq= %08x\n" ,
917 __func__, ch->pdu_seq);
919 ctcmpc_chx_rxidle(ch->fsm, CTC_EVENT_START, ch);
920 /* Put the write channel in idle state */
921 ch = priv->channel[WRITE];
922 if (ch->collect_len > 0) {
923 spin_lock(&ch->collect_lock);
924 ctcm_purge_skb_queue(&ch->collect_queue);
926 spin_unlock(&ch->collect_lock);
928 ctcm_chx_txidle(ch->fsm, CTC_EVENT_START, ch);
929 ctcm_clear_busy(dev);
931 if (grp->estconnfunc) {
932 grp->estconnfunc(grp->port_num, 0,
933 grp->group_max_buflen);
934 grp->estconnfunc = NULL;
935 } else if (grp->allochanfunc)
936 grp->allochanfunc(grp->port_num, grp->group_max_buflen);
938 grp->send_qllc_disc = 1;
939 grp->changed_side = 0;
946 * Increment the MPC Group Active Channel Counts
947 * helper of dev_action (called from channel fsm)
949 void mpc_channel_action(struct channel *ch, int direction, int action)
951 struct net_device *dev = ch->netdev;
952 struct ctcm_priv *priv = dev->ml_priv;
953 struct mpc_group *grp = priv->mpcg;
956 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
957 "%s(%s): No MPC group",
958 CTCM_FUNTAIL, dev->name);
962 CTCM_PR_DEBUG("enter %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
964 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
965 "%s: %i / Grp:%s total_channels=%i, active_channels: "
966 "read=%i, write=%i\n", __func__, action,
967 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
968 grp->active_channels[READ], grp->active_channels[WRITE]);
970 if ((action == MPC_CHANNEL_ADD) && (ch->in_mpcgroup == 0)) {
971 grp->num_channel_paths++;
972 grp->active_channels[direction]++;
973 grp->outstanding_xid2++;
976 if (ch->xid_skb != NULL)
977 dev_kfree_skb_any(ch->xid_skb);
979 ch->xid_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT,
980 GFP_ATOMIC | GFP_DMA);
981 if (ch->xid_skb == NULL) {
982 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
983 "%s(%s): Couldn't alloc ch xid_skb\n",
984 CTCM_FUNTAIL, dev->name);
985 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
988 ch->xid_skb_data = ch->xid_skb->data;
989 ch->xid_th = (struct th_header *)ch->xid_skb->data;
990 skb_put(ch->xid_skb, TH_HEADER_LENGTH);
991 ch->xid = (struct xid2 *)skb_tail_pointer(ch->xid_skb);
992 skb_put(ch->xid_skb, XID2_LENGTH);
993 ch->xid_id = skb_tail_pointer(ch->xid_skb);
994 ch->xid_skb->data = ch->xid_skb_data;
995 skb_reset_tail_pointer(ch->xid_skb);
996 ch->xid_skb->len = 0;
998 memcpy(skb_put(ch->xid_skb, grp->xid_skb->len),
1002 ch->xid->xid2_dlc_type = ((CHANNEL_DIRECTION(ch->flags) == READ)
1003 ? XID2_READ_SIDE : XID2_WRITE_SIDE);
1005 if (CHANNEL_DIRECTION(ch->flags) == WRITE)
1006 ch->xid->xid2_buf_len = 0x00;
1008 ch->xid_skb->data = ch->xid_skb_data;
1009 skb_reset_tail_pointer(ch->xid_skb);
1010 ch->xid_skb->len = 0;
1012 fsm_newstate(ch->fsm, CH_XID0_PENDING);
1014 if ((grp->active_channels[READ] > 0) &&
1015 (grp->active_channels[WRITE] > 0) &&
1016 (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) {
1017 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);
1018 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
1019 "%s: %s: MPC GROUP CHANNELS ACTIVE\n",
1020 __func__, dev->name);
1022 } else if ((action == MPC_CHANNEL_REMOVE) &&
1023 (ch->in_mpcgroup == 1)) {
1024 ch->in_mpcgroup = 0;
1025 grp->num_channel_paths--;
1026 grp->active_channels[direction]--;
1028 if (ch->xid_skb != NULL)
1029 dev_kfree_skb_any(ch->xid_skb);
1032 if (grp->channels_terminating)
1035 if (((grp->active_channels[READ] == 0) &&
1036 (grp->active_channels[WRITE] > 0))
1037 || ((grp->active_channels[WRITE] == 0) &&
1038 (grp->active_channels[READ] > 0)))
1039 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1042 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1043 "exit %s: %i / Grp:%s total_channels=%i, active_channels: "
1044 "read=%i, write=%i\n", __func__, action,
1045 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
1046 grp->active_channels[READ], grp->active_channels[WRITE]);
1048 CTCM_PR_DEBUG("exit %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
1052 * Unpack a just received skb and hand it over to
1054 * special MPC version of unpack_skb.
1056 * ch The channel where this skb has been received.
1057 * pskb The received skb.
1059 static void ctcmpc_unpack_skb(struct channel *ch, struct sk_buff *pskb)
1061 struct net_device *dev = ch->netdev;
1062 struct ctcm_priv *priv = dev->ml_priv;
1063 struct mpc_group *grp = priv->mpcg;
1064 struct pdu *curr_pdu;
1065 struct mpcg_info *mpcginfo;
1066 struct th_header *header = NULL;
1067 struct th_sweep *sweep = NULL;
1068 int pdu_last_seen = 0;
1070 struct sk_buff *skb;
1074 CTCM_PR_DEBUG("ctcmpc enter: %s() %s cp:%i ch:%s\n",
1075 __func__, dev->name, smp_processor_id(), ch->id);
1077 header = (struct th_header *)pskb->data;
1078 if ((header->th_seg == 0) &&
1079 (header->th_ch_flag == 0) &&
1080 (header->th_blk_flag == 0) &&
1081 (header->th_seq_num == 0))
1082 /* nothing for us */ goto done;
1084 CTCM_PR_DBGDATA("%s: th_header\n", __func__);
1085 CTCM_D3_DUMP((char *)header, TH_HEADER_LENGTH);
1086 CTCM_PR_DBGDATA("%s: pskb len: %04x \n", __func__, pskb->len);
1089 pskb->ip_summed = CHECKSUM_UNNECESSARY;
1090 skb_pull(pskb, TH_HEADER_LENGTH);
1092 if (likely(header->th_ch_flag == TH_HAS_PDU)) {
1093 CTCM_PR_DBGDATA("%s: came into th_has_pdu\n", __func__);
1094 if ((fsm_getstate(grp->fsm) == MPCG_STATE_FLOWC) ||
1095 ((fsm_getstate(grp->fsm) == MPCG_STATE_READY) &&
1096 (header->th_seq_num != ch->th_seq_num + 1) &&
1097 (ch->th_seq_num != 0))) {
1098 /* This is NOT the next segment *
1099 * we are not the correct race winner *
1100 * go away and let someone else win *
1101 * BUT..this only applies if xid negot *
1104 grp->out_of_sequence += 1;
1105 __skb_push(pskb, TH_HEADER_LENGTH);
1106 skb_queue_tail(&ch->io_queue, pskb);
1107 CTCM_PR_DBGDATA("%s: th_seq_num expect:%08x "
1108 "got:%08x\n", __func__,
1109 ch->th_seq_num + 1, header->th_seq_num);
1113 grp->out_of_sequence = 0;
1114 ch->th_seq_num = header->th_seq_num;
1116 CTCM_PR_DBGDATA("ctcmpc: %s() FromVTAM_th_seq=%08x\n",
1117 __func__, ch->th_seq_num);
1119 if (unlikely(fsm_getstate(grp->fsm) != MPCG_STATE_READY))
1122 while ((pskb->len > 0) && !pdu_last_seen) {
1123 curr_pdu = (struct pdu *)pskb->data;
1125 CTCM_PR_DBGDATA("%s: pdu_header\n", __func__);
1126 CTCM_D3_DUMP((char *)pskb->data, PDU_HEADER_LENGTH);
1127 CTCM_PR_DBGDATA("%s: pskb len: %04x \n",
1128 __func__, pskb->len);
1130 skb_pull(pskb, PDU_HEADER_LENGTH);
1132 if (curr_pdu->pdu_flag & PDU_LAST)
1134 if (curr_pdu->pdu_flag & PDU_CNTL)
1135 pskb->protocol = htons(ETH_P_SNAP);
1137 pskb->protocol = htons(ETH_P_SNA_DIX);
1139 if ((pskb->len <= 0) || (pskb->len > ch->max_bufsize)) {
1140 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1141 "%s(%s): Dropping packet with "
1143 CTCM_FUNTAIL, dev->name, pskb->len);
1145 priv->stats.rx_dropped++;
1146 priv->stats.rx_length_errors++;
1149 skb_reset_mac_header(pskb);
1150 new_len = curr_pdu->pdu_offset;
1151 CTCM_PR_DBGDATA("%s: new_len: %04x \n",
1153 if ((new_len == 0) || (new_len > pskb->len)) {
1154 /* should never happen */
1155 /* pskb len must be hosed...bail out */
1156 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1157 "%s(%s): non valid pdu_offset: %04x",
1158 /* "data may be lost", */
1159 CTCM_FUNTAIL, dev->name, new_len);
1162 skb = __dev_alloc_skb(new_len+4, GFP_ATOMIC);
1165 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1166 "%s(%s): MEMORY allocation error",
1167 CTCM_FUNTAIL, dev->name);
1168 priv->stats.rx_dropped++;
1169 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1172 memcpy(skb_put(skb, new_len), pskb->data, new_len);
1174 skb_reset_mac_header(skb);
1175 skb->dev = pskb->dev;
1176 skb->protocol = pskb->protocol;
1177 skb->ip_summed = CHECKSUM_UNNECESSARY;
1178 *((__u32 *) skb_push(skb, 4)) = ch->pdu_seq;
1181 if (do_debug_data) {
1182 ctcm_pr_debug("%s: ToDCM_pdu_seq= %08x\n",
1183 __func__, ch->pdu_seq);
1184 ctcm_pr_debug("%s: skb:%0lx "
1185 "skb len: %d \n", __func__,
1186 (unsigned long)skb, skb->len);
1187 ctcm_pr_debug("%s: up to 32 bytes "
1188 "of pdu_data sent\n", __func__);
1189 ctcmpc_dump32((char *)skb->data, skb->len);
1193 sendrc = netif_rx(skb);
1194 priv->stats.rx_packets++;
1195 priv->stats.rx_bytes += skblen;
1196 skb_pull(pskb, new_len); /* point to next PDU */
1199 mpcginfo = (struct mpcg_info *)
1200 kmalloc(sizeof(struct mpcg_info), gfp_type());
1201 if (mpcginfo == NULL)
1205 mpcginfo->th = header;
1206 mpcginfo->skb = pskb;
1207 CTCM_PR_DEBUG("%s: Not PDU - may be control pkt\n",
1210 sweep = (struct th_sweep *)pskb->data;
1211 mpcginfo->sweep = sweep;
1212 if (header->th_ch_flag == TH_SWEEP_REQ)
1213 mpc_rcvd_sweep_req(mpcginfo);
1214 else if (header->th_ch_flag == TH_SWEEP_RESP)
1215 mpc_rcvd_sweep_resp(mpcginfo);
1216 else if (header->th_blk_flag == TH_DATA_IS_XID) {
1217 struct xid2 *thisxid = (struct xid2 *)pskb->data;
1218 skb_pull(pskb, XID2_LENGTH);
1219 mpcginfo->xid = thisxid;
1220 fsm_event(grp->fsm, MPCG_EVENT_XID2, mpcginfo);
1221 } else if (header->th_blk_flag == TH_DISCONTACT)
1222 fsm_event(grp->fsm, MPCG_EVENT_DISCONC, mpcginfo);
1223 else if (header->th_seq_num != 0) {
1224 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1225 "%s(%s): control pkt expected\n",
1226 CTCM_FUNTAIL, dev->name);
1227 priv->stats.rx_dropped++;
1228 /* mpcginfo only used for non-data transfers */
1231 ctcmpc_dump_skb(pskb, -8);
1236 dev_kfree_skb_any(pskb);
1237 if (sendrc == NET_RX_DROP) {
1239 "The network backlog for %s is exceeded, "
1240 "package dropped\n", __func__);
1241 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1244 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1245 __func__, dev->name, ch, ch->id);
1249 * tasklet helper for mpc's skb unpacking.
1251 * ch The channel to work on.
1252 * Allow flow control back pressure to occur here.
1253 * Throttling back channel can result in excessive
1254 * channel inactivity and system deact of channel
1256 void ctcmpc_bh(unsigned long thischan)
1258 struct channel *ch = (struct channel *)thischan;
1259 struct sk_buff *skb;
1260 struct net_device *dev = ch->netdev;
1261 struct ctcm_priv *priv = dev->ml_priv;
1262 struct mpc_group *grp = priv->mpcg;
1264 CTCM_PR_DEBUG("%s cp:%i enter: %s() %s\n",
1265 dev->name, smp_processor_id(), __func__, ch->id);
1266 /* caller has requested driver to throttle back */
1267 while ((fsm_getstate(grp->fsm) != MPCG_STATE_FLOWC) &&
1268 (skb = skb_dequeue(&ch->io_queue))) {
1269 ctcmpc_unpack_skb(ch, skb);
1270 if (grp->out_of_sequence > 20) {
1271 /* assume data loss has occurred if */
1272 /* missing seq_num for extended */
1273 /* period of time */
1274 grp->out_of_sequence = 0;
1275 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1278 if (skb == skb_peek(&ch->io_queue))
1281 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1282 __func__, dev->name, ch, ch->id);
1287 * MPC Group Initializations
1289 struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv)
1291 struct mpc_group *grp;
1293 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
1294 "Enter %s(%p)", CTCM_FUNTAIL, priv);
1296 grp = kzalloc(sizeof(struct mpc_group), GFP_KERNEL);
1300 grp->fsm = init_fsm("mpcg", mpcg_state_names, mpcg_event_names,
1301 MPCG_NR_STATES, MPCG_NR_EVENTS, mpcg_fsm,
1302 mpcg_fsm_len, GFP_KERNEL);
1303 if (grp->fsm == NULL) {
1308 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1309 fsm_settimer(grp->fsm, &grp->timer);
1312 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC | GFP_DMA);
1313 if (grp->xid_skb == NULL) {
1314 kfree_fsm(grp->fsm);
1318 /* base xid for all channels in group */
1319 grp->xid_skb_data = grp->xid_skb->data;
1320 grp->xid_th = (struct th_header *)grp->xid_skb->data;
1321 memcpy(skb_put(grp->xid_skb, TH_HEADER_LENGTH),
1322 &thnorm, TH_HEADER_LENGTH);
1324 grp->xid = (struct xid2 *)skb_tail_pointer(grp->xid_skb);
1325 memcpy(skb_put(grp->xid_skb, XID2_LENGTH), &init_xid, XID2_LENGTH);
1326 grp->xid->xid2_adj_id = jiffies | 0xfff00000;
1327 grp->xid->xid2_sender_id = jiffies;
1329 grp->xid_id = skb_tail_pointer(grp->xid_skb);
1330 memcpy(skb_put(grp->xid_skb, 4), "VTAM", 4);
1333 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
1334 if (grp->rcvd_xid_skb == NULL) {
1335 kfree_fsm(grp->fsm);
1336 dev_kfree_skb(grp->xid_skb);
1340 grp->rcvd_xid_data = grp->rcvd_xid_skb->data;
1341 grp->rcvd_xid_th = (struct th_header *)grp->rcvd_xid_skb->data;
1342 memcpy(skb_put(grp->rcvd_xid_skb, TH_HEADER_LENGTH),
1343 &thnorm, TH_HEADER_LENGTH);
1344 grp->saved_xid2 = NULL;
1345 priv->xid = grp->xid;
1351 * The MPC Group Station FSM
1355 * MPC Group Station FSM actions
1356 * CTCM_PROTO_MPC only
1360 * NOP action for statemachines
1362 static void mpc_action_nop(fsm_instance *fi, int event, void *arg)
1367 * invoked when the device transitions to dev_stopped
1368 * MPC will stop each individual channel if a single XID failure
1369 * occurs, or will intitiate all channels be stopped if a GROUP
1370 * level failure occurs.
1372 static void mpc_action_go_inop(fsm_instance *fi, int event, void *arg)
1374 struct net_device *dev = arg;
1375 struct ctcm_priv *priv;
1376 struct mpc_group *grp;
1378 struct channel *wch, *rch;
1380 BUG_ON(dev == NULL);
1381 CTCM_PR_DEBUG("Enter %s: %s\n", __func__, dev->name);
1383 priv = dev->ml_priv;
1385 grp->flow_off_called = 0;
1386 fsm_deltimer(&grp->timer);
1387 if (grp->channels_terminating)
1390 grp->channels_terminating = 1;
1391 grp->saved_state = fsm_getstate(grp->fsm);
1392 fsm_newstate(grp->fsm, MPCG_STATE_INOP);
1393 if (grp->saved_state > MPCG_STATE_XID7INITF)
1394 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1395 "%s(%s): MPC GROUP INOPERATIVE",
1396 CTCM_FUNTAIL, dev->name);
1397 if ((grp->saved_state != MPCG_STATE_RESET) ||
1398 /* dealloc_channel has been called */
1399 ((grp->saved_state == MPCG_STATE_RESET) &&
1400 (grp->port_persist == 0)))
1401 fsm_deltimer(&priv->restart_timer);
1403 wch = priv->channel[WRITE];
1404 rch = priv->channel[READ];
1406 switch (grp->saved_state) {
1407 case MPCG_STATE_RESET:
1408 case MPCG_STATE_INOP:
1409 case MPCG_STATE_XID2INITW:
1410 case MPCG_STATE_XID0IOWAIT:
1411 case MPCG_STATE_XID2INITX:
1412 case MPCG_STATE_XID7INITW:
1413 case MPCG_STATE_XID7INITX:
1414 case MPCG_STATE_XID0IOWAIX:
1415 case MPCG_STATE_XID7INITI:
1416 case MPCG_STATE_XID7INITZ:
1417 case MPCG_STATE_XID7INITF:
1419 case MPCG_STATE_FLOWC:
1420 case MPCG_STATE_READY:
1422 tasklet_hi_schedule(&wch->ch_disc_tasklet);
1425 grp->xid2_tgnum = 0;
1426 grp->group_max_buflen = 0; /*min of all received */
1427 grp->outstanding_xid2 = 0;
1428 grp->outstanding_xid7 = 0;
1429 grp->outstanding_xid7_p2 = 0;
1430 grp->saved_xid2 = NULL;
1432 grp->changed_side = 0;
1434 grp->rcvd_xid_skb->data = grp->rcvd_xid_data;
1435 skb_reset_tail_pointer(grp->rcvd_xid_skb);
1436 grp->rcvd_xid_skb->len = 0;
1437 grp->rcvd_xid_th = (struct th_header *)grp->rcvd_xid_skb->data;
1438 memcpy(skb_put(grp->rcvd_xid_skb, TH_HEADER_LENGTH), &thnorm,
1441 if (grp->send_qllc_disc == 1) {
1442 grp->send_qllc_disc = 0;
1443 rc = mpc_send_qllc_discontact(dev);
1446 /* DO NOT issue DEV_EVENT_STOP directly out of this code */
1447 /* This can result in INOP of VTAM PU due to halting of */
1448 /* outstanding IO which causes a sense to be returned */
1449 /* Only about 3 senses are allowed and then IOS/VTAM will*/
1450 /* become unreachable without manual intervention */
1451 if ((grp->port_persist == 1) || (grp->alloc_called)) {
1452 grp->alloc_called = 0;
1453 fsm_deltimer(&priv->restart_timer);
1454 fsm_addtimer(&priv->restart_timer, 500, DEV_EVENT_RESTART, dev);
1455 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1456 if (grp->saved_state > MPCG_STATE_XID7INITF)
1457 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ALWAYS,
1458 "%s(%s): MPC GROUP RECOVERY SCHEDULED",
1459 CTCM_FUNTAIL, dev->name);
1461 fsm_deltimer(&priv->restart_timer);
1462 fsm_addtimer(&priv->restart_timer, 500, DEV_EVENT_STOP, dev);
1463 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1464 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ALWAYS,
1465 "%s(%s): NO MPC GROUP RECOVERY ATTEMPTED",
1466 CTCM_FUNTAIL, dev->name);
1471 * Handle mpc group action timeout.
1472 * MPC Group Station FSM action
1473 * CTCM_PROTO_MPC only
1475 * fi An instance of an mpc_group fsm.
1476 * event The event, just happened.
1477 * arg Generic pointer, casted from net_device * upon call.
1479 static void mpc_action_timeout(fsm_instance *fi, int event, void *arg)
1481 struct net_device *dev = arg;
1482 struct ctcm_priv *priv;
1483 struct mpc_group *grp;
1484 struct channel *wch;
1485 struct channel *rch;
1487 BUG_ON(dev == NULL);
1489 priv = dev->ml_priv;
1491 wch = priv->channel[WRITE];
1492 rch = priv->channel[READ];
1494 switch (fsm_getstate(grp->fsm)) {
1495 case MPCG_STATE_XID2INITW:
1496 /* Unless there is outstanding IO on the */
1497 /* channel just return and wait for ATTN */
1498 /* interrupt to begin XID negotiations */
1499 if ((fsm_getstate(rch->fsm) == CH_XID0_PENDING) &&
1500 (fsm_getstate(wch->fsm) == CH_XID0_PENDING))
1503 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1506 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1508 CTCM_FUNTAIL, dev->name);
1513 * MPC Group Station FSM action
1514 * CTCM_PROTO_MPC only
1516 void mpc_action_discontact(fsm_instance *fi, int event, void *arg)
1518 struct mpcg_info *mpcginfo = arg;
1519 struct channel *ch = mpcginfo->ch;
1520 struct net_device *dev;
1521 struct ctcm_priv *priv;
1522 struct mpc_group *grp;
1527 priv = dev->ml_priv;
1529 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1531 CTCM_FUNTAIL, dev->name, ch->id);
1533 grp->send_qllc_disc = 1;
1534 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1543 * MPC Group Station - not part of FSM
1544 * CTCM_PROTO_MPC only
1545 * called from add_channel in ctcm_main.c
1547 void mpc_action_send_discontact(unsigned long thischan)
1550 struct channel *ch = (struct channel *)thischan;
1551 unsigned long saveflags = 0;
1553 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1554 rc = ccw_device_start(ch->cdev, &ch->ccw[15],
1555 (unsigned long)ch, 0xff, 0);
1556 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1559 ctcm_ccw_check_rc(ch, rc, (char *)__func__);
1567 * helper function of mpc FSM
1568 * CTCM_PROTO_MPC only
1569 * mpc_action_rcvd_xid7
1571 static int mpc_validate_xid(struct mpcg_info *mpcginfo)
1573 struct channel *ch = mpcginfo->ch;
1574 struct net_device *dev = ch->netdev;
1575 struct ctcm_priv *priv = dev->ml_priv;
1576 struct mpc_group *grp = priv->mpcg;
1577 struct xid2 *xid = mpcginfo->xid;
1581 int len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1583 CTCM_PR_DEBUG("Enter %s: xid=%p\n", __func__, xid);
1587 /* XID REJECTED: xid == NULL */
1588 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1589 "%s(%s): xid = NULL",
1590 CTCM_FUNTAIL, ch->id);
1594 CTCM_D3_DUMP((char *)xid, XID2_LENGTH);
1596 /*the received direction should be the opposite of ours */
1597 if (((CHANNEL_DIRECTION(ch->flags) == READ) ? XID2_WRITE_SIDE :
1598 XID2_READ_SIDE) != xid->xid2_dlc_type) {
1600 /* XID REJECTED: r/w channel pairing mismatch */
1601 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1602 "%s(%s): r/w channel pairing mismatch",
1603 CTCM_FUNTAIL, ch->id);
1607 if (xid->xid2_dlc_type == XID2_READ_SIDE) {
1608 CTCM_PR_DEBUG("%s: grpmaxbuf:%d xid2buflen:%d\n", __func__,
1609 grp->group_max_buflen, xid->xid2_buf_len);
1611 if (grp->group_max_buflen == 0 || grp->group_max_buflen >
1612 xid->xid2_buf_len - len)
1613 grp->group_max_buflen = xid->xid2_buf_len - len;
1616 if (grp->saved_xid2 == NULL) {
1618 (struct xid2 *)skb_tail_pointer(grp->rcvd_xid_skb);
1620 memcpy(skb_put(grp->rcvd_xid_skb,
1621 XID2_LENGTH), xid, XID2_LENGTH);
1622 grp->rcvd_xid_skb->data = grp->rcvd_xid_data;
1624 skb_reset_tail_pointer(grp->rcvd_xid_skb);
1625 grp->rcvd_xid_skb->len = 0;
1627 /* convert two 32 bit numbers into 1 64 bit for id compare */
1628 our_id = (__u64)priv->xid->xid2_adj_id;
1629 our_id = our_id << 32;
1630 our_id = our_id + priv->xid->xid2_sender_id;
1631 their_id = (__u64)xid->xid2_adj_id;
1632 their_id = their_id << 32;
1633 their_id = their_id + xid->xid2_sender_id;
1634 /* lower id assume the xside role */
1635 if (our_id < their_id) {
1637 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1638 "%s(%s): WE HAVE LOW ID - TAKE XSIDE",
1639 CTCM_FUNTAIL, ch->id);
1642 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1643 "%s(%s): WE HAVE HIGH ID - TAKE YSIDE",
1644 CTCM_FUNTAIL, ch->id);
1648 if (xid->xid2_flag4 != grp->saved_xid2->xid2_flag4) {
1650 /* XID REJECTED: xid flag byte4 mismatch */
1651 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1652 "%s(%s): xid flag byte4 mismatch",
1653 CTCM_FUNTAIL, ch->id);
1655 if (xid->xid2_flag2 == 0x40) {
1657 /* XID REJECTED - xid NOGOOD */
1658 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1659 "%s(%s): xid NOGOOD",
1660 CTCM_FUNTAIL, ch->id);
1662 if (xid->xid2_adj_id != grp->saved_xid2->xid2_adj_id) {
1664 /* XID REJECTED - Adjacent Station ID Mismatch */
1665 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1666 "%s(%s): Adjacent Station ID Mismatch",
1667 CTCM_FUNTAIL, ch->id);
1669 if (xid->xid2_sender_id != grp->saved_xid2->xid2_sender_id) {
1671 /* XID REJECTED - Sender Address Mismatch */
1672 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1673 "%s(%s): Sender Address Mismatch",
1674 CTCM_FUNTAIL, ch->id);
1680 "The XID used in the MPC protocol is not valid, "
1682 priv->xid->xid2_flag2 = 0x40;
1683 grp->saved_xid2->xid2_flag2 = 0x40;
1690 * MPC Group Station FSM action
1691 * CTCM_PROTO_MPC only
1693 static void mpc_action_side_xid(fsm_instance *fsm, void *arg, int side)
1695 struct channel *ch = arg;
1698 unsigned long saveflags = 0; /* avoids compiler warning with
1699 spin_unlock_irqrestore */
1701 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1702 __func__, smp_processor_id(), ch, ch->id);
1704 if (ctcm_checkalloc_buffer(ch))
1708 * skb data-buffer referencing:
1710 ch->trans_skb->data = ch->trans_skb_data;
1711 skb_reset_tail_pointer(ch->trans_skb);
1712 ch->trans_skb->len = 0;
1713 /* result of the previous 3 statements is NOT always
1714 * already set after ctcm_checkalloc_buffer
1715 * because of possible reuse of the trans_skb
1717 memset(ch->trans_skb->data, 0, 16);
1718 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1719 /* check is main purpose here: */
1720 skb_put(ch->trans_skb, TH_HEADER_LENGTH);
1721 ch->rcvd_xid = (struct xid2 *)skb_tail_pointer(ch->trans_skb);
1722 /* check is main purpose here: */
1723 skb_put(ch->trans_skb, XID2_LENGTH);
1724 ch->rcvd_xid_id = skb_tail_pointer(ch->trans_skb);
1725 /* cleanup back to startpoint */
1726 ch->trans_skb->data = ch->trans_skb_data;
1727 skb_reset_tail_pointer(ch->trans_skb);
1728 ch->trans_skb->len = 0;
1730 /* non-checking rewrite of above skb data-buffer referencing: */
1732 memset(ch->trans_skb->data, 0, 16);
1733 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1734 ch->rcvd_xid = (struct xid2 *)(ch->trans_skb_data + TH_HEADER_LENGTH);
1735 ch->rcvd_xid_id = ch->trans_skb_data + TH_HEADER_LENGTH + XID2_LENGTH;
1738 ch->ccw[8].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1739 ch->ccw[8].count = 0;
1740 ch->ccw[8].cda = 0x00;
1742 if (!(ch->xid_th && ch->xid && ch->xid_id))
1743 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_INFO,
1744 "%s(%s): xid_th=%p, xid=%p, xid_id=%p",
1745 CTCM_FUNTAIL, ch->id, ch->xid_th, ch->xid, ch->xid_id);
1747 if (side == XSIDE) {
1748 /* mpc_action_xside_xid */
1749 if (ch->xid_th == NULL)
1751 ch->ccw[9].cmd_code = CCW_CMD_WRITE;
1752 ch->ccw[9].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1753 ch->ccw[9].count = TH_HEADER_LENGTH;
1754 ch->ccw[9].cda = virt_to_phys(ch->xid_th);
1756 if (ch->xid == NULL)
1758 ch->ccw[10].cmd_code = CCW_CMD_WRITE;
1759 ch->ccw[10].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1760 ch->ccw[10].count = XID2_LENGTH;
1761 ch->ccw[10].cda = virt_to_phys(ch->xid);
1763 ch->ccw[11].cmd_code = CCW_CMD_READ;
1764 ch->ccw[11].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1765 ch->ccw[11].count = TH_HEADER_LENGTH;
1766 ch->ccw[11].cda = virt_to_phys(ch->rcvd_xid_th);
1768 ch->ccw[12].cmd_code = CCW_CMD_READ;
1769 ch->ccw[12].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1770 ch->ccw[12].count = XID2_LENGTH;
1771 ch->ccw[12].cda = virt_to_phys(ch->rcvd_xid);
1773 ch->ccw[13].cmd_code = CCW_CMD_READ;
1774 ch->ccw[13].cda = virt_to_phys(ch->rcvd_xid_id);
1776 } else { /* side == YSIDE : mpc_action_yside_xid */
1777 ch->ccw[9].cmd_code = CCW_CMD_READ;
1778 ch->ccw[9].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1779 ch->ccw[9].count = TH_HEADER_LENGTH;
1780 ch->ccw[9].cda = virt_to_phys(ch->rcvd_xid_th);
1782 ch->ccw[10].cmd_code = CCW_CMD_READ;
1783 ch->ccw[10].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1784 ch->ccw[10].count = XID2_LENGTH;
1785 ch->ccw[10].cda = virt_to_phys(ch->rcvd_xid);
1787 if (ch->xid_th == NULL)
1789 ch->ccw[11].cmd_code = CCW_CMD_WRITE;
1790 ch->ccw[11].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1791 ch->ccw[11].count = TH_HEADER_LENGTH;
1792 ch->ccw[11].cda = virt_to_phys(ch->xid_th);
1794 if (ch->xid == NULL)
1796 ch->ccw[12].cmd_code = CCW_CMD_WRITE;
1797 ch->ccw[12].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1798 ch->ccw[12].count = XID2_LENGTH;
1799 ch->ccw[12].cda = virt_to_phys(ch->xid);
1801 if (ch->xid_id == NULL)
1803 ch->ccw[13].cmd_code = CCW_CMD_WRITE;
1804 ch->ccw[13].cda = virt_to_phys(ch->xid_id);
1807 ch->ccw[13].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1808 ch->ccw[13].count = 4;
1810 ch->ccw[14].cmd_code = CCW_CMD_NOOP;
1811 ch->ccw[14].flags = CCW_FLAG_SLI;
1812 ch->ccw[14].count = 0;
1813 ch->ccw[14].cda = 0;
1815 CTCM_CCW_DUMP((char *)&ch->ccw[8], sizeof(struct ccw1) * 7);
1816 CTCM_D3_DUMP((char *)ch->xid_th, TH_HEADER_LENGTH);
1817 CTCM_D3_DUMP((char *)ch->xid, XID2_LENGTH);
1818 CTCM_D3_DUMP((char *)ch->xid_id, 4);
1821 /* Such conditional locking is a known problem for
1822 * sparse because its static undeterministic.
1823 * Warnings should be ignored here. */
1824 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1828 fsm_addtimer(&ch->timer, 5000 , CTC_EVENT_TIMER, ch);
1829 rc = ccw_device_start(ch->cdev, &ch->ccw[8],
1830 (unsigned long)ch, 0xff, 0);
1832 if (gotlock) /* see remark above about conditional locking */
1833 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1836 ctcm_ccw_check_rc(ch, rc,
1837 (side == XSIDE) ? "x-side XID" : "y-side XID");
1841 CTCM_PR_DEBUG("Exit %s: ch=0x%p id=%s\n",
1842 __func__, ch, ch->id);
1848 * MPC Group Station FSM action
1849 * CTCM_PROTO_MPC only
1851 static void mpc_action_xside_xid(fsm_instance *fsm, int event, void *arg)
1853 mpc_action_side_xid(fsm, arg, XSIDE);
1857 * MPC Group Station FSM action
1858 * CTCM_PROTO_MPC only
1860 static void mpc_action_yside_xid(fsm_instance *fsm, int event, void *arg)
1862 mpc_action_side_xid(fsm, arg, YSIDE);
1866 * MPC Group Station FSM action
1867 * CTCM_PROTO_MPC only
1869 static void mpc_action_doxid0(fsm_instance *fsm, int event, void *arg)
1871 struct channel *ch = arg;
1872 struct net_device *dev = ch->netdev;
1873 struct ctcm_priv *priv = dev->ml_priv;
1874 struct mpc_group *grp = priv->mpcg;
1876 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1877 __func__, smp_processor_id(), ch, ch->id);
1879 if (ch->xid == NULL) {
1880 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1881 "%s(%s): ch->xid == NULL",
1882 CTCM_FUNTAIL, dev->name);
1886 fsm_newstate(ch->fsm, CH_XID0_INPROGRESS);
1888 ch->xid->xid2_option = XID2_0;
1890 switch (fsm_getstate(grp->fsm)) {
1891 case MPCG_STATE_XID2INITW:
1892 case MPCG_STATE_XID2INITX:
1893 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1895 case MPCG_STATE_XID0IOWAIT:
1896 case MPCG_STATE_XID0IOWAIX:
1897 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1901 fsm_event(grp->fsm, MPCG_EVENT_DOIO, ch);
1907 * MPC Group Station FSM action
1908 * CTCM_PROTO_MPC only
1910 static void mpc_action_doxid7(fsm_instance *fsm, int event, void *arg)
1912 struct net_device *dev = arg;
1913 struct ctcm_priv *priv = dev->ml_priv;
1914 struct mpc_group *grp = NULL;
1921 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1925 for (direction = READ; direction <= WRITE; direction++) {
1926 struct channel *ch = priv->channel[direction];
1927 struct xid2 *thisxid = ch->xid;
1928 ch->xid_skb->data = ch->xid_skb_data;
1929 skb_reset_tail_pointer(ch->xid_skb);
1930 ch->xid_skb->len = 0;
1931 thisxid->xid2_option = XID2_7;
1935 if (grp->outstanding_xid7_p2 > 0) {
1936 if (grp->roll == YSIDE) {
1937 if (fsm_getstate(ch->fsm) == CH_XID7_PENDING1) {
1938 fsm_newstate(ch->fsm, CH_XID7_PENDING2);
1939 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1940 memcpy(skb_put(ch->xid_skb,
1942 &thdummy, TH_HEADER_LENGTH);
1945 } else if (fsm_getstate(ch->fsm) < CH_XID7_PENDING2) {
1946 fsm_newstate(ch->fsm, CH_XID7_PENDING2);
1947 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1948 memcpy(skb_put(ch->xid_skb,
1950 &thnorm, TH_HEADER_LENGTH);
1955 if (grp->roll == YSIDE) {
1956 if (fsm_getstate(ch->fsm) < CH_XID7_PENDING4) {
1957 fsm_newstate(ch->fsm, CH_XID7_PENDING4);
1958 memcpy(skb_put(ch->xid_skb,
1960 &thnorm, TH_HEADER_LENGTH);
1961 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1964 } else if (fsm_getstate(ch->fsm) == CH_XID7_PENDING3) {
1965 fsm_newstate(ch->fsm, CH_XID7_PENDING4);
1966 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1967 memcpy(skb_put(ch->xid_skb, TH_HEADER_LENGTH),
1968 &thdummy, TH_HEADER_LENGTH);
1974 fsm_event(grp->fsm, MPCG_EVENT_DOIO, ch);
1981 * MPC Group Station FSM action
1982 * CTCM_PROTO_MPC only
1984 static void mpc_action_rcvd_xid0(fsm_instance *fsm, int event, void *arg)
1987 struct mpcg_info *mpcginfo = arg;
1988 struct channel *ch = mpcginfo->ch;
1989 struct net_device *dev = ch->netdev;
1990 struct ctcm_priv *priv = dev->ml_priv;
1991 struct mpc_group *grp = priv->mpcg;
1993 CTCM_PR_DEBUG("%s: ch-id:%s xid2:%i xid7:%i xidt_p2:%i \n",
1994 __func__, ch->id, grp->outstanding_xid2,
1995 grp->outstanding_xid7, grp->outstanding_xid7_p2);
1997 if (fsm_getstate(ch->fsm) < CH_XID7_PENDING)
1998 fsm_newstate(ch->fsm, CH_XID7_PENDING);
2000 grp->outstanding_xid2--;
2001 grp->outstanding_xid7++;
2002 grp->outstanding_xid7_p2++;
2004 /* must change state before validating xid to */
2005 /* properly handle interim interrupts received*/
2006 switch (fsm_getstate(grp->fsm)) {
2007 case MPCG_STATE_XID2INITW:
2008 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITX);
2009 mpc_validate_xid(mpcginfo);
2011 case MPCG_STATE_XID0IOWAIT:
2012 fsm_newstate(grp->fsm, MPCG_STATE_XID0IOWAIX);
2013 mpc_validate_xid(mpcginfo);
2015 case MPCG_STATE_XID2INITX:
2016 if (grp->outstanding_xid2 == 0) {
2017 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITW);
2018 mpc_validate_xid(mpcginfo);
2019 fsm_event(grp->fsm, MPCG_EVENT_XID2DONE, dev);
2022 case MPCG_STATE_XID0IOWAIX:
2023 if (grp->outstanding_xid2 == 0) {
2024 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITI);
2025 mpc_validate_xid(mpcginfo);
2026 fsm_event(grp->fsm, MPCG_EVENT_XID2DONE, dev);
2032 CTCM_PR_DEBUG("ctcmpc:%s() %s xid2:%i xid7:%i xidt_p2:%i \n",
2033 __func__, ch->id, grp->outstanding_xid2,
2034 grp->outstanding_xid7, grp->outstanding_xid7_p2);
2035 CTCM_PR_DEBUG("ctcmpc:%s() %s grpstate: %s chanstate: %s \n",
2037 fsm_getstate_str(grp->fsm), fsm_getstate_str(ch->fsm));
2044 * MPC Group Station FSM action
2045 * CTCM_PROTO_MPC only
2047 static void mpc_action_rcvd_xid7(fsm_instance *fsm, int event, void *arg)
2049 struct mpcg_info *mpcginfo = arg;
2050 struct channel *ch = mpcginfo->ch;
2051 struct net_device *dev = ch->netdev;
2052 struct ctcm_priv *priv = dev->ml_priv;
2053 struct mpc_group *grp = priv->mpcg;
2055 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
2056 __func__, smp_processor_id(), ch, ch->id);
2057 CTCM_PR_DEBUG("%s: outstanding_xid7: %i, outstanding_xid7_p2: %i\n",
2058 __func__, grp->outstanding_xid7, grp->outstanding_xid7_p2);
2060 grp->outstanding_xid7--;
2061 ch->xid_skb->data = ch->xid_skb_data;
2062 skb_reset_tail_pointer(ch->xid_skb);
2063 ch->xid_skb->len = 0;
2065 switch (fsm_getstate(grp->fsm)) {
2066 case MPCG_STATE_XID7INITI:
2067 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITZ);
2068 mpc_validate_xid(mpcginfo);
2070 case MPCG_STATE_XID7INITW:
2071 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITX);
2072 mpc_validate_xid(mpcginfo);
2074 case MPCG_STATE_XID7INITZ:
2075 case MPCG_STATE_XID7INITX:
2076 if (grp->outstanding_xid7 == 0) {
2077 if (grp->outstanding_xid7_p2 > 0) {
2078 grp->outstanding_xid7 =
2079 grp->outstanding_xid7_p2;
2080 grp->outstanding_xid7_p2 = 0;
2082 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITF);
2084 mpc_validate_xid(mpcginfo);
2085 fsm_event(grp->fsm, MPCG_EVENT_XID7DONE, dev);
2088 mpc_validate_xid(mpcginfo);
2096 * mpc_action helper of an MPC Group Station FSM action
2097 * CTCM_PROTO_MPC only
2099 static int mpc_send_qllc_discontact(struct net_device *dev)
2102 struct sk_buff *skb;
2103 struct qllc *qllcptr;
2104 struct ctcm_priv *priv = dev->ml_priv;
2105 struct mpc_group *grp = priv->mpcg;
2107 CTCM_PR_DEBUG("%s: GROUP STATE: %s\n",
2108 __func__, mpcg_state_names[grp->saved_state]);
2110 switch (grp->saved_state) {
2112 * establish conn callback function is
2113 * preferred method to report failure
2115 case MPCG_STATE_XID0IOWAIT:
2116 case MPCG_STATE_XID0IOWAIX:
2117 case MPCG_STATE_XID7INITI:
2118 case MPCG_STATE_XID7INITZ:
2119 case MPCG_STATE_XID2INITW:
2120 case MPCG_STATE_XID2INITX:
2121 case MPCG_STATE_XID7INITW:
2122 case MPCG_STATE_XID7INITX:
2123 if (grp->estconnfunc) {
2124 grp->estconnfunc(grp->port_num, -1, 0);
2125 grp->estconnfunc = NULL;
2128 case MPCG_STATE_FLOWC:
2129 case MPCG_STATE_READY:
2130 grp->send_qllc_disc = 2;
2131 new_len = sizeof(struct qllc);
2132 qllcptr = kzalloc(new_len, gfp_type() | GFP_DMA);
2133 if (qllcptr == NULL) {
2134 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2135 "%s(%s): qllcptr allocation error",
2136 CTCM_FUNTAIL, dev->name);
2140 qllcptr->qllc_address = 0xcc;
2141 qllcptr->qllc_commands = 0x03;
2143 skb = __dev_alloc_skb(new_len, GFP_ATOMIC);
2146 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2147 "%s(%s): skb allocation error",
2148 CTCM_FUNTAIL, dev->name);
2149 priv->stats.rx_dropped++;
2154 memcpy(skb_put(skb, new_len), qllcptr, new_len);
2157 if (skb_headroom(skb) < 4) {
2158 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2159 "%s(%s): skb_headroom error",
2160 CTCM_FUNTAIL, dev->name);
2161 dev_kfree_skb_any(skb);
2165 *((__u32 *)skb_push(skb, 4)) = priv->channel[READ]->pdu_seq;
2166 priv->channel[READ]->pdu_seq++;
2167 CTCM_PR_DBGDATA("ctcmpc: %s ToDCM_pdu_seq= %08x\n",
2168 __func__, priv->channel[READ]->pdu_seq);
2170 /* receipt of CC03 resets anticipated sequence number on
2172 priv->channel[READ]->pdu_seq = 0x00;
2173 skb_reset_mac_header(skb);
2175 skb->protocol = htons(ETH_P_SNAP);
2176 skb->ip_summed = CHECKSUM_UNNECESSARY;
2178 CTCM_D3_DUMP(skb->data, (sizeof(struct qllc) + 4));
2189 /* --- This is the END my friend --- */