1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2004, 2007
4 * Authors: Belinda Thompson (belindat@us.ibm.com)
5 * Andy Richter (richtera@us.ibm.com)
6 * Peter Tiedemann (ptiedem@de.ibm.com)
10 This module exports functions to be used by CCS:
11 EXPORT_SYMBOL(ctc_mpc_alloc_channel);
12 EXPORT_SYMBOL(ctc_mpc_establish_connectivity);
13 EXPORT_SYMBOL(ctc_mpc_dealloc_ch);
14 EXPORT_SYMBOL(ctc_mpc_flow_control);
21 #define KMSG_COMPONENT "ctcm"
22 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/errno.h>
29 #include <linux/types.h>
30 #include <linux/interrupt.h>
31 #include <linux/timer.h>
32 #include <linux/sched.h>
34 #include <linux/signal.h>
35 #include <linux/string.h>
36 #include <linux/proc_fs.h>
39 #include <linux/if_arp.h>
40 #include <linux/tcp.h>
41 #include <linux/skbuff.h>
42 #include <linux/ctype.h>
43 #include <linux/netdevice.h>
46 #include <linux/io.h> /* instead of <asm/io.h> ok ? */
47 #include <asm/ccwdev.h>
48 #include <asm/ccwgroup.h>
49 #include <linux/bitops.h> /* instead of <asm/bitops.h> ok ? */
50 #include <linux/uaccess.h> /* instead of <asm/uaccess.h> ok ? */
51 #include <linux/wait.h>
52 #include <linux/moduleparam.h>
53 #include <asm/idals.h>
55 #include "ctcm_main.h"
57 #include "ctcm_fsms.h"
59 static const struct xid2 init_xid = {
60 .xid2_type_id = XID_FM2,
72 .xid2_option = XID2_0,
75 .xid2_dlc_type = XID2_READ_SIDE,
79 .xid2_buf_len = (MPC_BUFSIZE_DEFAULT - 35),
82 static const struct th_header thnorm = {
84 .th_ch_flag = TH_IS_XID,
85 .th_blk_flag = TH_DATA_IS_XID,
87 .th_seq_num = 0x00000000,
90 static const struct th_header thdummy = {
93 .th_blk_flag = TH_DATA_IS_XID,
95 .th_seq_num = 0x00000000,
99 * Definition of one MPC group
103 * Compatibility macros for busy handling
104 * of network devices.
107 static void ctcmpc_unpack_skb(struct channel *ch, struct sk_buff *pskb);
110 * MPC Group state machine actions (static prototypes)
112 static void mpc_action_nop(fsm_instance *fsm, int event, void *arg);
113 static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg);
114 static void mpc_action_go_inop(fsm_instance *fi, int event, void *arg);
115 static void mpc_action_timeout(fsm_instance *fi, int event, void *arg);
116 static int mpc_validate_xid(struct mpcg_info *mpcginfo);
117 static void mpc_action_yside_xid(fsm_instance *fsm, int event, void *arg);
118 static void mpc_action_doxid0(fsm_instance *fsm, int event, void *arg);
119 static void mpc_action_doxid7(fsm_instance *fsm, int event, void *arg);
120 static void mpc_action_xside_xid(fsm_instance *fsm, int event, void *arg);
121 static void mpc_action_rcvd_xid0(fsm_instance *fsm, int event, void *arg);
122 static void mpc_action_rcvd_xid7(fsm_instance *fsm, int event, void *arg);
125 /*-------------------------------------------------------------------*
126 * Dump buffer format *
128 *--------------------------------------------------------------------*/
129 void ctcmpc_dumpit(char *buf, int len)
131 __u32 ct, sw, rm, dup;
133 char tbuf[82], tdup[82];
136 char bhex[82], duphex[82];
145 for (ct = 0; ct < len; ct++, ptr++, rptr++) {
147 sprintf(addr, "%16.16llx", (__u64)rptr);
149 sprintf(boff, "%4.4X", (__u32)ct);
153 if ((sw == 4) || (sw == 12))
158 sprintf(tbuf, "%2.2llX", (__u64)*ptr);
162 if ((0 != isprint(*ptr)) && (*ptr >= 0x20))
172 if ((strcmp(duphex, bhex)) != 0) {
175 "Duplicate as above to %s", addr);
176 ctcm_pr_debug(" --- %s ---\n",
179 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
180 addr, boff, bhex, basc);
182 strcpy(duphex, bhex);
191 for ( ; rm > 0; rm--, sw++) {
192 if ((sw == 4) || (sw == 12))
200 sprintf(tdup, "Duplicate as above to %s", addr);
201 ctcm_pr_debug(" --- %s ---\n", tdup);
203 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
204 addr, boff, bhex, basc);
207 sprintf(tdup, "Duplicate as above to %s", addr);
208 ctcm_pr_debug(" --- %s ---\n", tdup);
211 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
212 addr, boff, bhex, basc);
218 } /* end of ctcmpc_dumpit */
223 * Dump header and first 16 bytes of an sk_buff for debugging purposes.
225 * skb The sk_buff to dump.
226 * offset Offset relative to skb-data, where to start the dump.
228 void ctcmpc_dump_skb(struct sk_buff *skb, int offset)
231 struct th_header *header;
240 header = (struct th_header *)p;
242 ctcm_pr_debug("dump:\n");
243 ctcm_pr_debug("skb len=%d \n", skb->len);
245 switch (header->th_ch_flag) {
250 if ((header->th_blk_flag == TH_DATA_IS_XID) &&
251 (header->th_is_xid == 0x01))
261 pheader = (struct pdu *)p;
262 ctcm_pr_debug("pdu->offset: %d hex: %04x\n",
263 pheader->pdu_offset, pheader->pdu_offset);
264 ctcm_pr_debug("pdu->flag : %02x\n", pheader->pdu_flag);
265 ctcm_pr_debug("pdu->proto : %02x\n", pheader->pdu_proto);
266 ctcm_pr_debug("pdu->seq : %02x\n", pheader->pdu_seq);
270 ctcm_pr_debug("th->seg : %02x\n", header->th_seg);
271 ctcm_pr_debug("th->ch : %02x\n", header->th_ch_flag);
272 ctcm_pr_debug("th->blk_flag: %02x\n", header->th_blk_flag);
273 ctcm_pr_debug("th->type : %s\n",
274 (header->th_is_xid) ? "DATA" : "XID");
275 ctcm_pr_debug("th->seqnum : %04x\n", header->th_seq_num);
281 ctcm_pr_debug("data: ");
282 for (i = 0; i < bl; i++)
283 ctcm_pr_debug("%02x%s", *p++, (i % 16) ? " " : "\n");
288 static struct net_device *ctcmpc_get_dev(int port_num)
291 struct net_device *dev;
292 struct ctcm_priv *priv;
294 sprintf(device, "%s%i", MPC_DEVICE_NAME, port_num);
296 dev = __dev_get_by_name(&init_net, device);
299 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
300 "%s: Device not found by name: %s",
301 CTCM_FUNTAIL, device);
306 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
307 "%s(%s): dev->ml_priv is NULL",
308 CTCM_FUNTAIL, device);
311 if (priv->mpcg == NULL) {
312 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
313 "%s(%s): priv->mpcg is NULL",
314 CTCM_FUNTAIL, device);
321 * ctc_mpc_alloc_channel
322 * (exported interface)
324 * Device Initialization :
325 * ACTPATH driven IO operations
327 int ctc_mpc_alloc_channel(int port_num, void (*callback)(int, int))
329 struct net_device *dev;
330 struct mpc_group *grp;
331 struct ctcm_priv *priv;
333 dev = ctcmpc_get_dev(port_num);
339 grp->allochanfunc = callback;
340 grp->port_num = port_num;
341 grp->port_persist = 1;
343 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
345 CTCM_FUNTAIL, dev->name, fsm_getstate_str(grp->fsm));
347 switch (fsm_getstate(grp->fsm)) {
348 case MPCG_STATE_INOP:
349 /* Group is in the process of terminating */
350 grp->alloc_called = 1;
352 case MPCG_STATE_RESET:
353 /* MPC Group will transition to state */
354 /* MPCG_STATE_XID2INITW iff the minimum number */
355 /* of 1 read and 1 write channel have successfully*/
357 /*fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);*/
359 grp->send_qllc_disc = 1;
360 case MPCG_STATE_XID0IOWAIT:
361 fsm_deltimer(&grp->timer);
362 grp->outstanding_xid2 = 0;
363 grp->outstanding_xid7 = 0;
364 grp->outstanding_xid7_p2 = 0;
365 grp->saved_xid2 = NULL;
368 fsm_event(priv->fsm, DEV_EVENT_START, dev);
370 case MPCG_STATE_READY:
371 /* XID exchanges completed after PORT was activated */
372 /* Link station already active */
373 /* Maybe timing issue...retry callback */
374 grp->allocchan_callback_retries++;
375 if (grp->allocchan_callback_retries < 4) {
376 if (grp->allochanfunc)
377 grp->allochanfunc(grp->port_num,
378 grp->group_max_buflen);
380 /* there are problems...bail out */
381 /* there may be a state mismatch so restart */
382 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
383 grp->allocchan_callback_retries = 0;
390 EXPORT_SYMBOL(ctc_mpc_alloc_channel);
393 * ctc_mpc_establish_connectivity
394 * (exported interface)
396 void ctc_mpc_establish_connectivity(int port_num,
397 void (*callback)(int, int, int))
399 struct net_device *dev;
400 struct mpc_group *grp;
401 struct ctcm_priv *priv;
402 struct channel *rch, *wch;
404 dev = ctcmpc_get_dev(port_num);
409 rch = priv->channel[CTCM_READ];
410 wch = priv->channel[CTCM_WRITE];
412 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
414 CTCM_FUNTAIL, dev->name, fsm_getstate_str(grp->fsm));
416 grp->estconnfunc = callback;
417 grp->port_num = port_num;
419 switch (fsm_getstate(grp->fsm)) {
420 case MPCG_STATE_READY:
421 /* XID exchanges completed after PORT was activated */
422 /* Link station already active */
423 /* Maybe timing issue...retry callback */
424 fsm_deltimer(&grp->timer);
425 grp->estconn_callback_retries++;
426 if (grp->estconn_callback_retries < 4) {
427 if (grp->estconnfunc) {
428 grp->estconnfunc(grp->port_num, 0,
429 grp->group_max_buflen);
430 grp->estconnfunc = NULL;
433 /* there are problems...bail out */
434 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
435 grp->estconn_callback_retries = 0;
438 case MPCG_STATE_INOP:
439 case MPCG_STATE_RESET:
440 /* MPC Group is not ready to start XID - min num of */
441 /* 1 read and 1 write channel have not been acquired*/
443 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
444 "%s(%s): REJECTED - inactive channels",
445 CTCM_FUNTAIL, dev->name);
446 if (grp->estconnfunc) {
447 grp->estconnfunc(grp->port_num, -1, 0);
448 grp->estconnfunc = NULL;
451 case MPCG_STATE_XID2INITW:
452 /* alloc channel was called but no XID exchange */
453 /* has occurred. initiate xside XID exchange */
454 /* make sure yside XID0 processing has not started */
456 if ((fsm_getstate(rch->fsm) > CH_XID0_PENDING) ||
457 (fsm_getstate(wch->fsm) > CH_XID0_PENDING)) {
458 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
459 "%s(%s): ABORT - PASSIVE XID",
460 CTCM_FUNTAIL, dev->name);
463 grp->send_qllc_disc = 1;
464 fsm_newstate(grp->fsm, MPCG_STATE_XID0IOWAIT);
465 fsm_deltimer(&grp->timer);
466 fsm_addtimer(&grp->timer, MPC_XID_TIMEOUT_VALUE,
467 MPCG_EVENT_TIMER, dev);
468 grp->outstanding_xid7 = 0;
469 grp->outstanding_xid7_p2 = 0;
470 grp->saved_xid2 = NULL;
471 if ((rch->in_mpcgroup) &&
472 (fsm_getstate(rch->fsm) == CH_XID0_PENDING))
473 fsm_event(grp->fsm, MPCG_EVENT_XID0DO, rch);
475 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
476 "%s(%s): RX-%s not ready for ACTIVE XID0",
477 CTCM_FUNTAIL, dev->name, rch->id);
478 if (grp->estconnfunc) {
479 grp->estconnfunc(grp->port_num, -1, 0);
480 grp->estconnfunc = NULL;
482 fsm_deltimer(&grp->timer);
485 if ((wch->in_mpcgroup) &&
486 (fsm_getstate(wch->fsm) == CH_XID0_PENDING))
487 fsm_event(grp->fsm, MPCG_EVENT_XID0DO, wch);
489 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
490 "%s(%s): WX-%s not ready for ACTIVE XID0",
491 CTCM_FUNTAIL, dev->name, wch->id);
492 if (grp->estconnfunc) {
493 grp->estconnfunc(grp->port_num, -1, 0);
494 grp->estconnfunc = NULL;
496 fsm_deltimer(&grp->timer);
500 case MPCG_STATE_XID0IOWAIT:
501 /* already in active XID negotiations */
507 CTCM_PR_DEBUG("Exit %s()\n", __func__);
510 EXPORT_SYMBOL(ctc_mpc_establish_connectivity);
514 * (exported interface)
516 void ctc_mpc_dealloc_ch(int port_num)
518 struct net_device *dev;
519 struct ctcm_priv *priv;
520 struct mpc_group *grp;
522 dev = ctcmpc_get_dev(port_num);
528 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_DEBUG,
529 "%s: %s: refcount = %d\n",
530 CTCM_FUNTAIL, dev->name, netdev_refcnt_read(dev));
532 fsm_deltimer(&priv->restart_timer);
533 grp->channels_terminating = 0;
534 fsm_deltimer(&grp->timer);
535 grp->allochanfunc = NULL;
536 grp->estconnfunc = NULL;
537 grp->port_persist = 0;
538 grp->send_qllc_disc = 0;
539 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
544 EXPORT_SYMBOL(ctc_mpc_dealloc_ch);
547 * ctc_mpc_flow_control
548 * (exported interface)
550 void ctc_mpc_flow_control(int port_num, int flowc)
552 struct ctcm_priv *priv;
553 struct mpc_group *grp;
554 struct net_device *dev;
558 dev = ctcmpc_get_dev(port_num);
564 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
565 "%s: %s: flowc = %d",
566 CTCM_FUNTAIL, dev->name, flowc);
568 rch = priv->channel[CTCM_READ];
570 mpcg_state = fsm_getstate(grp->fsm);
573 if (mpcg_state == MPCG_STATE_FLOWC)
575 if (mpcg_state == MPCG_STATE_READY) {
576 if (grp->flow_off_called == 1)
577 grp->flow_off_called = 0;
579 fsm_newstate(grp->fsm, MPCG_STATE_FLOWC);
584 if (mpcg_state == MPCG_STATE_FLOWC) {
585 fsm_newstate(grp->fsm, MPCG_STATE_READY);
586 /* ensure any data that has accumulated */
587 /* on the io_queue will now be sen t */
588 tasklet_schedule(&rch->ch_tasklet);
590 /* possible race condition */
591 if (mpcg_state == MPCG_STATE_READY) {
592 grp->flow_off_called = 1;
599 EXPORT_SYMBOL(ctc_mpc_flow_control);
601 static int mpc_send_qllc_discontact(struct net_device *);
604 * helper function of ctcmpc_unpack_skb
606 static void mpc_rcvd_sweep_resp(struct mpcg_info *mpcginfo)
608 struct channel *rch = mpcginfo->ch;
609 struct net_device *dev = rch->netdev;
610 struct ctcm_priv *priv = dev->ml_priv;
611 struct mpc_group *grp = priv->mpcg;
612 struct channel *ch = priv->channel[CTCM_WRITE];
614 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, ch, ch->id);
615 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
617 grp->sweep_rsp_pend_num--;
619 if ((grp->sweep_req_pend_num == 0) &&
620 (grp->sweep_rsp_pend_num == 0)) {
621 fsm_deltimer(&ch->sweep_timer);
623 rch->th_seq_num = 0x00;
624 ch->th_seq_num = 0x00;
625 ctcm_clear_busy_do(dev);
633 * helper function of mpc_rcvd_sweep_req
634 * which is a helper of ctcmpc_unpack_skb
636 static void ctcmpc_send_sweep_resp(struct channel *rch)
638 struct net_device *dev = rch->netdev;
639 struct ctcm_priv *priv = dev->ml_priv;
640 struct mpc_group *grp = priv->mpcg;
641 struct th_sweep *header;
642 struct sk_buff *sweep_skb;
643 struct channel *ch = priv->channel[CTCM_WRITE];
645 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, rch, rch->id);
647 sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC | GFP_DMA);
648 if (sweep_skb == NULL) {
649 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
650 "%s(%s): sweep_skb allocation ERROR\n",
651 CTCM_FUNTAIL, rch->id);
655 header = kmalloc(sizeof(struct th_sweep), gfp_type());
658 dev_kfree_skb_any(sweep_skb);
662 header->th.th_seg = 0x00 ;
663 header->th.th_ch_flag = TH_SWEEP_RESP;
664 header->th.th_blk_flag = 0x00;
665 header->th.th_is_xid = 0x00;
666 header->th.th_seq_num = 0x00;
667 header->sw.th_last_seq = ch->th_seq_num;
669 skb_put_data(sweep_skb, header, TH_SWEEP_LENGTH);
673 netif_trans_update(dev);
674 skb_queue_tail(&ch->sweep_queue, sweep_skb);
676 fsm_addtimer(&ch->sweep_timer, 100, CTC_EVENT_RSWEEP_TIMER, ch);
682 ctcm_clear_busy_do(dev);
683 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
689 * helper function of ctcmpc_unpack_skb
691 static void mpc_rcvd_sweep_req(struct mpcg_info *mpcginfo)
693 struct channel *rch = mpcginfo->ch;
694 struct net_device *dev = rch->netdev;
695 struct ctcm_priv *priv = dev->ml_priv;
696 struct mpc_group *grp = priv->mpcg;
697 struct channel *ch = priv->channel[CTCM_WRITE];
700 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
701 " %s(): ch=0x%p id=%s\n", __func__, ch, ch->id);
703 if (grp->in_sweep == 0) {
705 ctcm_test_and_set_busy(dev);
706 grp->sweep_req_pend_num = grp->active_channels[CTCM_READ];
707 grp->sweep_rsp_pend_num = grp->active_channels[CTCM_READ];
710 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
712 grp->sweep_req_pend_num--;
713 ctcmpc_send_sweep_resp(ch);
719 * MPC Group Station FSM definitions
721 static const char *mpcg_event_names[] = {
722 [MPCG_EVENT_INOP] = "INOP Condition",
723 [MPCG_EVENT_DISCONC] = "Discontact Received",
724 [MPCG_EVENT_XID0DO] = "Channel Active - Start XID",
725 [MPCG_EVENT_XID2] = "XID2 Received",
726 [MPCG_EVENT_XID2DONE] = "XID0 Complete",
727 [MPCG_EVENT_XID7DONE] = "XID7 Complete",
728 [MPCG_EVENT_TIMER] = "XID Setup Timer",
729 [MPCG_EVENT_DOIO] = "XID DoIO",
732 static const char *mpcg_state_names[] = {
733 [MPCG_STATE_RESET] = "Reset",
734 [MPCG_STATE_INOP] = "INOP",
735 [MPCG_STATE_XID2INITW] = "Passive XID- XID0 Pending Start",
736 [MPCG_STATE_XID2INITX] = "Passive XID- XID0 Pending Complete",
737 [MPCG_STATE_XID7INITW] = "Passive XID- XID7 Pending P1 Start",
738 [MPCG_STATE_XID7INITX] = "Passive XID- XID7 Pending P2 Complete",
739 [MPCG_STATE_XID0IOWAIT] = "Active XID- XID0 Pending Start",
740 [MPCG_STATE_XID0IOWAIX] = "Active XID- XID0 Pending Complete",
741 [MPCG_STATE_XID7INITI] = "Active XID- XID7 Pending Start",
742 [MPCG_STATE_XID7INITZ] = "Active XID- XID7 Pending Complete ",
743 [MPCG_STATE_XID7INITF] = "XID - XID7 Complete ",
744 [MPCG_STATE_FLOWC] = "FLOW CONTROL ON",
745 [MPCG_STATE_READY] = "READY",
749 * The MPC Group Station FSM
752 static const fsm_node mpcg_fsm[] = {
753 { MPCG_STATE_RESET, MPCG_EVENT_INOP, mpc_action_go_inop },
754 { MPCG_STATE_INOP, MPCG_EVENT_INOP, mpc_action_nop },
755 { MPCG_STATE_FLOWC, MPCG_EVENT_INOP, mpc_action_go_inop },
757 { MPCG_STATE_READY, MPCG_EVENT_DISCONC, mpc_action_discontact },
758 { MPCG_STATE_READY, MPCG_EVENT_INOP, mpc_action_go_inop },
760 { MPCG_STATE_XID2INITW, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
761 { MPCG_STATE_XID2INITW, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
762 { MPCG_STATE_XID2INITW, MPCG_EVENT_INOP, mpc_action_go_inop },
763 { MPCG_STATE_XID2INITW, MPCG_EVENT_TIMER, mpc_action_timeout },
764 { MPCG_STATE_XID2INITW, MPCG_EVENT_DOIO, mpc_action_yside_xid },
766 { MPCG_STATE_XID2INITX, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
767 { MPCG_STATE_XID2INITX, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
768 { MPCG_STATE_XID2INITX, MPCG_EVENT_INOP, mpc_action_go_inop },
769 { MPCG_STATE_XID2INITX, MPCG_EVENT_TIMER, mpc_action_timeout },
770 { MPCG_STATE_XID2INITX, MPCG_EVENT_DOIO, mpc_action_yside_xid },
772 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID2DONE, mpc_action_doxid7 },
773 { MPCG_STATE_XID7INITW, MPCG_EVENT_DISCONC, mpc_action_discontact },
774 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
775 { MPCG_STATE_XID7INITW, MPCG_EVENT_INOP, mpc_action_go_inop },
776 { MPCG_STATE_XID7INITW, MPCG_EVENT_TIMER, mpc_action_timeout },
777 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
778 { MPCG_STATE_XID7INITW, MPCG_EVENT_DOIO, mpc_action_yside_xid },
780 { MPCG_STATE_XID7INITX, MPCG_EVENT_DISCONC, mpc_action_discontact },
781 { MPCG_STATE_XID7INITX, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
782 { MPCG_STATE_XID7INITX, MPCG_EVENT_INOP, mpc_action_go_inop },
783 { MPCG_STATE_XID7INITX, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
784 { MPCG_STATE_XID7INITX, MPCG_EVENT_TIMER, mpc_action_timeout },
785 { MPCG_STATE_XID7INITX, MPCG_EVENT_DOIO, mpc_action_yside_xid },
787 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
788 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_DISCONC, mpc_action_discontact },
789 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
790 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_INOP, mpc_action_go_inop },
791 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_TIMER, mpc_action_timeout },
792 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_DOIO, mpc_action_xside_xid },
794 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
795 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_DISCONC, mpc_action_discontact },
796 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
797 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_INOP, mpc_action_go_inop },
798 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_TIMER, mpc_action_timeout },
799 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_DOIO, mpc_action_xside_xid },
801 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID2DONE, mpc_action_doxid7 },
802 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
803 { MPCG_STATE_XID7INITI, MPCG_EVENT_DISCONC, mpc_action_discontact },
804 { MPCG_STATE_XID7INITI, MPCG_EVENT_INOP, mpc_action_go_inop },
805 { MPCG_STATE_XID7INITI, MPCG_EVENT_TIMER, mpc_action_timeout },
806 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
807 { MPCG_STATE_XID7INITI, MPCG_EVENT_DOIO, mpc_action_xside_xid },
809 { MPCG_STATE_XID7INITZ, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
810 { MPCG_STATE_XID7INITZ, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
811 { MPCG_STATE_XID7INITZ, MPCG_EVENT_DISCONC, mpc_action_discontact },
812 { MPCG_STATE_XID7INITZ, MPCG_EVENT_INOP, mpc_action_go_inop },
813 { MPCG_STATE_XID7INITZ, MPCG_EVENT_TIMER, mpc_action_timeout },
814 { MPCG_STATE_XID7INITZ, MPCG_EVENT_DOIO, mpc_action_xside_xid },
816 { MPCG_STATE_XID7INITF, MPCG_EVENT_INOP, mpc_action_go_inop },
817 { MPCG_STATE_XID7INITF, MPCG_EVENT_XID7DONE, mpc_action_go_ready },
820 static int mpcg_fsm_len = ARRAY_SIZE(mpcg_fsm);
823 * MPC Group Station FSM action
824 * CTCM_PROTO_MPC only
826 static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg)
828 struct net_device *dev = arg;
829 struct ctcm_priv *priv = dev->ml_priv;
830 struct mpc_group *grp = priv->mpcg;
833 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
834 "%s(%s): No MPC group",
835 CTCM_FUNTAIL, dev->name);
839 fsm_deltimer(&grp->timer);
841 if (grp->saved_xid2->xid2_flag2 == 0x40) {
842 priv->xid->xid2_flag2 = 0x00;
843 if (grp->estconnfunc) {
844 grp->estconnfunc(grp->port_num, 1,
845 grp->group_max_buflen);
846 grp->estconnfunc = NULL;
847 } else if (grp->allochanfunc)
848 grp->send_qllc_disc = 1;
850 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
851 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
853 CTCM_FUNTAIL, dev->name);
857 grp->port_persist = 1;
858 grp->out_of_sequence = 0;
859 grp->estconn_called = 0;
861 tasklet_hi_schedule(&grp->mpc_tasklet2);
867 * helper of ctcm_init_netdevice
868 * CTCM_PROTO_MPC only
870 void mpc_group_ready(unsigned long adev)
872 struct net_device *dev = (struct net_device *)adev;
873 struct ctcm_priv *priv = dev->ml_priv;
874 struct mpc_group *grp = priv->mpcg;
875 struct channel *ch = NULL;
878 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
879 "%s(%s): No MPC group",
880 CTCM_FUNTAIL, dev->name);
884 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
885 "%s: %s: GROUP TRANSITIONED TO READY, maxbuf = %d\n",
886 CTCM_FUNTAIL, dev->name, grp->group_max_buflen);
888 fsm_newstate(grp->fsm, MPCG_STATE_READY);
890 /* Put up a read on the channel */
891 ch = priv->channel[CTCM_READ];
893 CTCM_PR_DBGDATA("ctcmpc: %s() ToDCM_pdu_seq= %08x\n" ,
894 __func__, ch->pdu_seq);
896 ctcmpc_chx_rxidle(ch->fsm, CTC_EVENT_START, ch);
897 /* Put the write channel in idle state */
898 ch = priv->channel[CTCM_WRITE];
899 if (ch->collect_len > 0) {
900 spin_lock(&ch->collect_lock);
901 ctcm_purge_skb_queue(&ch->collect_queue);
903 spin_unlock(&ch->collect_lock);
905 ctcm_chx_txidle(ch->fsm, CTC_EVENT_START, ch);
906 ctcm_clear_busy(dev);
908 if (grp->estconnfunc) {
909 grp->estconnfunc(grp->port_num, 0,
910 grp->group_max_buflen);
911 grp->estconnfunc = NULL;
912 } else if (grp->allochanfunc)
913 grp->allochanfunc(grp->port_num, grp->group_max_buflen);
915 grp->send_qllc_disc = 1;
916 grp->changed_side = 0;
923 * Increment the MPC Group Active Channel Counts
924 * helper of dev_action (called from channel fsm)
926 void mpc_channel_action(struct channel *ch, int direction, int action)
928 struct net_device *dev = ch->netdev;
929 struct ctcm_priv *priv = dev->ml_priv;
930 struct mpc_group *grp = priv->mpcg;
933 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
934 "%s(%s): No MPC group",
935 CTCM_FUNTAIL, dev->name);
939 CTCM_PR_DEBUG("enter %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
941 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
942 "%s: %i / Grp:%s total_channels=%i, active_channels: "
943 "read=%i, write=%i\n", __func__, action,
944 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
945 grp->active_channels[CTCM_READ],
946 grp->active_channels[CTCM_WRITE]);
948 if ((action == MPC_CHANNEL_ADD) && (ch->in_mpcgroup == 0)) {
949 grp->num_channel_paths++;
950 grp->active_channels[direction]++;
951 grp->outstanding_xid2++;
954 if (ch->xid_skb != NULL)
955 dev_kfree_skb_any(ch->xid_skb);
957 ch->xid_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT,
958 GFP_ATOMIC | GFP_DMA);
959 if (ch->xid_skb == NULL) {
960 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
961 "%s(%s): Couldn't alloc ch xid_skb\n",
962 CTCM_FUNTAIL, dev->name);
963 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
966 ch->xid_skb_data = ch->xid_skb->data;
967 ch->xid_th = (struct th_header *)ch->xid_skb->data;
968 skb_put(ch->xid_skb, TH_HEADER_LENGTH);
969 ch->xid = (struct xid2 *)skb_tail_pointer(ch->xid_skb);
970 skb_put(ch->xid_skb, XID2_LENGTH);
971 ch->xid_id = skb_tail_pointer(ch->xid_skb);
972 ch->xid_skb->data = ch->xid_skb_data;
973 skb_reset_tail_pointer(ch->xid_skb);
974 ch->xid_skb->len = 0;
976 skb_put_data(ch->xid_skb, grp->xid_skb->data,
979 ch->xid->xid2_dlc_type =
980 ((CHANNEL_DIRECTION(ch->flags) == CTCM_READ)
981 ? XID2_READ_SIDE : XID2_WRITE_SIDE);
983 if (CHANNEL_DIRECTION(ch->flags) == CTCM_WRITE)
984 ch->xid->xid2_buf_len = 0x00;
986 ch->xid_skb->data = ch->xid_skb_data;
987 skb_reset_tail_pointer(ch->xid_skb);
988 ch->xid_skb->len = 0;
990 fsm_newstate(ch->fsm, CH_XID0_PENDING);
992 if ((grp->active_channels[CTCM_READ] > 0) &&
993 (grp->active_channels[CTCM_WRITE] > 0) &&
994 (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) {
995 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);
996 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
997 "%s: %s: MPC GROUP CHANNELS ACTIVE\n",
998 __func__, dev->name);
1000 } else if ((action == MPC_CHANNEL_REMOVE) &&
1001 (ch->in_mpcgroup == 1)) {
1002 ch->in_mpcgroup = 0;
1003 grp->num_channel_paths--;
1004 grp->active_channels[direction]--;
1006 if (ch->xid_skb != NULL)
1007 dev_kfree_skb_any(ch->xid_skb);
1010 if (grp->channels_terminating)
1013 if (((grp->active_channels[CTCM_READ] == 0) &&
1014 (grp->active_channels[CTCM_WRITE] > 0))
1015 || ((grp->active_channels[CTCM_WRITE] == 0) &&
1016 (grp->active_channels[CTCM_READ] > 0)))
1017 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1020 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1021 "exit %s: %i / Grp:%s total_channels=%i, active_channels: "
1022 "read=%i, write=%i\n", __func__, action,
1023 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
1024 grp->active_channels[CTCM_READ],
1025 grp->active_channels[CTCM_WRITE]);
1027 CTCM_PR_DEBUG("exit %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
1031 * Unpack a just received skb and hand it over to
1033 * special MPC version of unpack_skb.
1035 * ch The channel where this skb has been received.
1036 * pskb The received skb.
1038 static void ctcmpc_unpack_skb(struct channel *ch, struct sk_buff *pskb)
1040 struct net_device *dev = ch->netdev;
1041 struct ctcm_priv *priv = dev->ml_priv;
1042 struct mpc_group *grp = priv->mpcg;
1043 struct pdu *curr_pdu;
1044 struct mpcg_info *mpcginfo;
1045 struct th_header *header = NULL;
1046 struct th_sweep *sweep = NULL;
1047 int pdu_last_seen = 0;
1049 struct sk_buff *skb;
1053 CTCM_PR_DEBUG("ctcmpc enter: %s() %s cp:%i ch:%s\n",
1054 __func__, dev->name, smp_processor_id(), ch->id);
1056 header = (struct th_header *)pskb->data;
1057 if ((header->th_seg == 0) &&
1058 (header->th_ch_flag == 0) &&
1059 (header->th_blk_flag == 0) &&
1060 (header->th_seq_num == 0))
1061 /* nothing for us */ goto done;
1063 CTCM_PR_DBGDATA("%s: th_header\n", __func__);
1064 CTCM_D3_DUMP((char *)header, TH_HEADER_LENGTH);
1065 CTCM_PR_DBGDATA("%s: pskb len: %04x \n", __func__, pskb->len);
1068 pskb->ip_summed = CHECKSUM_UNNECESSARY;
1069 skb_pull(pskb, TH_HEADER_LENGTH);
1071 if (likely(header->th_ch_flag == TH_HAS_PDU)) {
1072 CTCM_PR_DBGDATA("%s: came into th_has_pdu\n", __func__);
1073 if ((fsm_getstate(grp->fsm) == MPCG_STATE_FLOWC) ||
1074 ((fsm_getstate(grp->fsm) == MPCG_STATE_READY) &&
1075 (header->th_seq_num != ch->th_seq_num + 1) &&
1076 (ch->th_seq_num != 0))) {
1077 /* This is NOT the next segment *
1078 * we are not the correct race winner *
1079 * go away and let someone else win *
1080 * BUT..this only applies if xid negot *
1083 grp->out_of_sequence += 1;
1084 __skb_push(pskb, TH_HEADER_LENGTH);
1085 skb_queue_tail(&ch->io_queue, pskb);
1086 CTCM_PR_DBGDATA("%s: th_seq_num expect:%08x "
1087 "got:%08x\n", __func__,
1088 ch->th_seq_num + 1, header->th_seq_num);
1092 grp->out_of_sequence = 0;
1093 ch->th_seq_num = header->th_seq_num;
1095 CTCM_PR_DBGDATA("ctcmpc: %s() FromVTAM_th_seq=%08x\n",
1096 __func__, ch->th_seq_num);
1098 if (unlikely(fsm_getstate(grp->fsm) != MPCG_STATE_READY))
1100 while ((pskb->len > 0) && !pdu_last_seen) {
1101 curr_pdu = (struct pdu *)pskb->data;
1103 CTCM_PR_DBGDATA("%s: pdu_header\n", __func__);
1104 CTCM_D3_DUMP((char *)pskb->data, PDU_HEADER_LENGTH);
1105 CTCM_PR_DBGDATA("%s: pskb len: %04x \n",
1106 __func__, pskb->len);
1108 skb_pull(pskb, PDU_HEADER_LENGTH);
1110 if (curr_pdu->pdu_flag & PDU_LAST)
1112 if (curr_pdu->pdu_flag & PDU_CNTL)
1113 pskb->protocol = htons(ETH_P_SNAP);
1115 pskb->protocol = htons(ETH_P_SNA_DIX);
1117 if ((pskb->len <= 0) || (pskb->len > ch->max_bufsize)) {
1118 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1119 "%s(%s): Dropping packet with "
1121 CTCM_FUNTAIL, dev->name, pskb->len);
1123 priv->stats.rx_dropped++;
1124 priv->stats.rx_length_errors++;
1127 skb_reset_mac_header(pskb);
1128 new_len = curr_pdu->pdu_offset;
1129 CTCM_PR_DBGDATA("%s: new_len: %04x \n",
1131 if ((new_len == 0) || (new_len > pskb->len)) {
1132 /* should never happen */
1133 /* pskb len must be hosed...bail out */
1134 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1135 "%s(%s): non valid pdu_offset: %04x",
1136 /* "data may be lost", */
1137 CTCM_FUNTAIL, dev->name, new_len);
1140 skb = __dev_alloc_skb(new_len+4, GFP_ATOMIC);
1143 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1144 "%s(%s): MEMORY allocation error",
1145 CTCM_FUNTAIL, dev->name);
1146 priv->stats.rx_dropped++;
1147 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1150 skb_put_data(skb, pskb->data, new_len);
1152 skb_reset_mac_header(skb);
1153 skb->dev = pskb->dev;
1154 skb->protocol = pskb->protocol;
1155 skb->ip_summed = CHECKSUM_UNNECESSARY;
1156 *((__u32 *) skb_push(skb, 4)) = ch->pdu_seq;
1159 if (do_debug_data) {
1160 ctcm_pr_debug("%s: ToDCM_pdu_seq= %08x\n",
1161 __func__, ch->pdu_seq);
1162 ctcm_pr_debug("%s: skb:%0lx "
1163 "skb len: %d \n", __func__,
1164 (unsigned long)skb, skb->len);
1165 ctcm_pr_debug("%s: up to 32 bytes "
1166 "of pdu_data sent\n", __func__);
1167 ctcmpc_dump32((char *)skb->data, skb->len);
1171 sendrc = netif_rx(skb);
1172 priv->stats.rx_packets++;
1173 priv->stats.rx_bytes += skblen;
1174 skb_pull(pskb, new_len); /* point to next PDU */
1177 mpcginfo = kmalloc(sizeof(struct mpcg_info), gfp_type());
1178 if (mpcginfo == NULL)
1182 mpcginfo->th = header;
1183 mpcginfo->skb = pskb;
1184 CTCM_PR_DEBUG("%s: Not PDU - may be control pkt\n",
1187 sweep = (struct th_sweep *)pskb->data;
1188 mpcginfo->sweep = sweep;
1189 if (header->th_ch_flag == TH_SWEEP_REQ)
1190 mpc_rcvd_sweep_req(mpcginfo);
1191 else if (header->th_ch_flag == TH_SWEEP_RESP)
1192 mpc_rcvd_sweep_resp(mpcginfo);
1193 else if (header->th_blk_flag == TH_DATA_IS_XID) {
1194 struct xid2 *thisxid = (struct xid2 *)pskb->data;
1195 skb_pull(pskb, XID2_LENGTH);
1196 mpcginfo->xid = thisxid;
1197 fsm_event(grp->fsm, MPCG_EVENT_XID2, mpcginfo);
1198 } else if (header->th_blk_flag == TH_DISCONTACT)
1199 fsm_event(grp->fsm, MPCG_EVENT_DISCONC, mpcginfo);
1200 else if (header->th_seq_num != 0) {
1201 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1202 "%s(%s): control pkt expected\n",
1203 CTCM_FUNTAIL, dev->name);
1204 priv->stats.rx_dropped++;
1205 /* mpcginfo only used for non-data transfers */
1207 ctcmpc_dump_skb(pskb, -8);
1213 dev_kfree_skb_any(pskb);
1214 if (sendrc == NET_RX_DROP) {
1216 "The network backlog for %s is exceeded, "
1217 "package dropped\n", __func__);
1218 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1221 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1222 __func__, dev->name, ch, ch->id);
1226 * tasklet helper for mpc's skb unpacking.
1228 * ch The channel to work on.
1229 * Allow flow control back pressure to occur here.
1230 * Throttling back channel can result in excessive
1231 * channel inactivity and system deact of channel
1233 void ctcmpc_bh(unsigned long thischan)
1235 struct channel *ch = (struct channel *)thischan;
1236 struct sk_buff *skb;
1237 struct net_device *dev = ch->netdev;
1238 struct ctcm_priv *priv = dev->ml_priv;
1239 struct mpc_group *grp = priv->mpcg;
1241 CTCM_PR_DEBUG("%s cp:%i enter: %s() %s\n",
1242 dev->name, smp_processor_id(), __func__, ch->id);
1243 /* caller has requested driver to throttle back */
1244 while ((fsm_getstate(grp->fsm) != MPCG_STATE_FLOWC) &&
1245 (skb = skb_dequeue(&ch->io_queue))) {
1246 ctcmpc_unpack_skb(ch, skb);
1247 if (grp->out_of_sequence > 20) {
1248 /* assume data loss has occurred if */
1249 /* missing seq_num for extended */
1250 /* period of time */
1251 grp->out_of_sequence = 0;
1252 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1255 if (skb == skb_peek(&ch->io_queue))
1258 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1259 __func__, dev->name, ch, ch->id);
1264 * MPC Group Initializations
1266 struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv)
1268 struct mpc_group *grp;
1270 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
1271 "Enter %s(%p)", CTCM_FUNTAIL, priv);
1273 grp = kzalloc(sizeof(struct mpc_group), GFP_KERNEL);
1277 grp->fsm = init_fsm("mpcg", mpcg_state_names, mpcg_event_names,
1278 MPCG_NR_STATES, MPCG_NR_EVENTS, mpcg_fsm,
1279 mpcg_fsm_len, GFP_KERNEL);
1280 if (grp->fsm == NULL) {
1285 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1286 fsm_settimer(grp->fsm, &grp->timer);
1289 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC | GFP_DMA);
1290 if (grp->xid_skb == NULL) {
1291 kfree_fsm(grp->fsm);
1295 /* base xid for all channels in group */
1296 grp->xid_skb_data = grp->xid_skb->data;
1297 grp->xid_th = (struct th_header *)grp->xid_skb->data;
1298 skb_put_data(grp->xid_skb, &thnorm, TH_HEADER_LENGTH);
1300 grp->xid = (struct xid2 *)skb_tail_pointer(grp->xid_skb);
1301 skb_put_data(grp->xid_skb, &init_xid, XID2_LENGTH);
1302 grp->xid->xid2_adj_id = jiffies | 0xfff00000;
1303 grp->xid->xid2_sender_id = jiffies;
1305 grp->xid_id = skb_tail_pointer(grp->xid_skb);
1306 skb_put_data(grp->xid_skb, "VTAM", 4);
1309 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
1310 if (grp->rcvd_xid_skb == NULL) {
1311 kfree_fsm(grp->fsm);
1312 dev_kfree_skb(grp->xid_skb);
1316 grp->rcvd_xid_data = grp->rcvd_xid_skb->data;
1317 grp->rcvd_xid_th = (struct th_header *)grp->rcvd_xid_skb->data;
1318 skb_put_data(grp->rcvd_xid_skb, &thnorm, TH_HEADER_LENGTH);
1319 grp->saved_xid2 = NULL;
1320 priv->xid = grp->xid;
1326 * The MPC Group Station FSM
1330 * MPC Group Station FSM actions
1331 * CTCM_PROTO_MPC only
1335 * NOP action for statemachines
1337 static void mpc_action_nop(fsm_instance *fi, int event, void *arg)
1342 * invoked when the device transitions to dev_stopped
1343 * MPC will stop each individual channel if a single XID failure
1344 * occurs, or will intitiate all channels be stopped if a GROUP
1345 * level failure occurs.
1347 static void mpc_action_go_inop(fsm_instance *fi, int event, void *arg)
1349 struct net_device *dev = arg;
1350 struct ctcm_priv *priv;
1351 struct mpc_group *grp;
1352 struct channel *wch;
1354 CTCM_PR_DEBUG("Enter %s: %s\n", __func__, dev->name);
1356 priv = dev->ml_priv;
1358 grp->flow_off_called = 0;
1359 fsm_deltimer(&grp->timer);
1360 if (grp->channels_terminating)
1363 grp->channels_terminating = 1;
1364 grp->saved_state = fsm_getstate(grp->fsm);
1365 fsm_newstate(grp->fsm, MPCG_STATE_INOP);
1366 if (grp->saved_state > MPCG_STATE_XID7INITF)
1367 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1368 "%s(%s): MPC GROUP INOPERATIVE",
1369 CTCM_FUNTAIL, dev->name);
1370 if ((grp->saved_state != MPCG_STATE_RESET) ||
1371 /* dealloc_channel has been called */
1372 (grp->port_persist == 0))
1373 fsm_deltimer(&priv->restart_timer);
1375 wch = priv->channel[CTCM_WRITE];
1377 switch (grp->saved_state) {
1378 case MPCG_STATE_RESET:
1379 case MPCG_STATE_INOP:
1380 case MPCG_STATE_XID2INITW:
1381 case MPCG_STATE_XID0IOWAIT:
1382 case MPCG_STATE_XID2INITX:
1383 case MPCG_STATE_XID7INITW:
1384 case MPCG_STATE_XID7INITX:
1385 case MPCG_STATE_XID0IOWAIX:
1386 case MPCG_STATE_XID7INITI:
1387 case MPCG_STATE_XID7INITZ:
1388 case MPCG_STATE_XID7INITF:
1390 case MPCG_STATE_FLOWC:
1391 case MPCG_STATE_READY:
1393 tasklet_hi_schedule(&wch->ch_disc_tasklet);
1396 grp->xid2_tgnum = 0;
1397 grp->group_max_buflen = 0; /*min of all received */
1398 grp->outstanding_xid2 = 0;
1399 grp->outstanding_xid7 = 0;
1400 grp->outstanding_xid7_p2 = 0;
1401 grp->saved_xid2 = NULL;
1403 grp->changed_side = 0;
1405 grp->rcvd_xid_skb->data = grp->rcvd_xid_data;
1406 skb_reset_tail_pointer(grp->rcvd_xid_skb);
1407 grp->rcvd_xid_skb->len = 0;
1408 grp->rcvd_xid_th = (struct th_header *)grp->rcvd_xid_skb->data;
1409 skb_put_data(grp->rcvd_xid_skb, &thnorm, TH_HEADER_LENGTH);
1411 if (grp->send_qllc_disc == 1) {
1412 grp->send_qllc_disc = 0;
1413 mpc_send_qllc_discontact(dev);
1416 /* DO NOT issue DEV_EVENT_STOP directly out of this code */
1417 /* This can result in INOP of VTAM PU due to halting of */
1418 /* outstanding IO which causes a sense to be returned */
1419 /* Only about 3 senses are allowed and then IOS/VTAM will*/
1420 /* become unreachable without manual intervention */
1421 if ((grp->port_persist == 1) || (grp->alloc_called)) {
1422 grp->alloc_called = 0;
1423 fsm_deltimer(&priv->restart_timer);
1424 fsm_addtimer(&priv->restart_timer, 500, DEV_EVENT_RESTART, dev);
1425 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1426 if (grp->saved_state > MPCG_STATE_XID7INITF)
1427 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ALWAYS,
1428 "%s(%s): MPC GROUP RECOVERY SCHEDULED",
1429 CTCM_FUNTAIL, dev->name);
1431 fsm_deltimer(&priv->restart_timer);
1432 fsm_addtimer(&priv->restart_timer, 500, DEV_EVENT_STOP, dev);
1433 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1434 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ALWAYS,
1435 "%s(%s): NO MPC GROUP RECOVERY ATTEMPTED",
1436 CTCM_FUNTAIL, dev->name);
1441 * Handle mpc group action timeout.
1442 * MPC Group Station FSM action
1443 * CTCM_PROTO_MPC only
1445 * fi An instance of an mpc_group fsm.
1446 * event The event, just happened.
1447 * arg Generic pointer, casted from net_device * upon call.
1449 static void mpc_action_timeout(fsm_instance *fi, int event, void *arg)
1451 struct net_device *dev = arg;
1452 struct ctcm_priv *priv;
1453 struct mpc_group *grp;
1454 struct channel *wch;
1455 struct channel *rch;
1457 priv = dev->ml_priv;
1459 wch = priv->channel[CTCM_WRITE];
1460 rch = priv->channel[CTCM_READ];
1462 switch (fsm_getstate(grp->fsm)) {
1463 case MPCG_STATE_XID2INITW:
1464 /* Unless there is outstanding IO on the */
1465 /* channel just return and wait for ATTN */
1466 /* interrupt to begin XID negotiations */
1467 if ((fsm_getstate(rch->fsm) == CH_XID0_PENDING) &&
1468 (fsm_getstate(wch->fsm) == CH_XID0_PENDING))
1471 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1474 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1476 CTCM_FUNTAIL, dev->name);
1481 * MPC Group Station FSM action
1482 * CTCM_PROTO_MPC only
1484 void mpc_action_discontact(fsm_instance *fi, int event, void *arg)
1486 struct mpcg_info *mpcginfo = arg;
1487 struct channel *ch = mpcginfo->ch;
1488 struct net_device *dev;
1489 struct ctcm_priv *priv;
1490 struct mpc_group *grp;
1495 priv = dev->ml_priv;
1497 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1499 CTCM_FUNTAIL, dev->name, ch->id);
1501 grp->send_qllc_disc = 1;
1502 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1511 * MPC Group Station - not part of FSM
1512 * CTCM_PROTO_MPC only
1513 * called from add_channel in ctcm_main.c
1515 void mpc_action_send_discontact(unsigned long thischan)
1518 struct channel *ch = (struct channel *)thischan;
1519 unsigned long saveflags = 0;
1521 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1522 rc = ccw_device_start(ch->cdev, &ch->ccw[15],
1523 (unsigned long)ch, 0xff, 0);
1524 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1527 ctcm_ccw_check_rc(ch, rc, (char *)__func__);
1535 * helper function of mpc FSM
1536 * CTCM_PROTO_MPC only
1537 * mpc_action_rcvd_xid7
1539 static int mpc_validate_xid(struct mpcg_info *mpcginfo)
1541 struct channel *ch = mpcginfo->ch;
1542 struct net_device *dev = ch->netdev;
1543 struct ctcm_priv *priv = dev->ml_priv;
1544 struct mpc_group *grp = priv->mpcg;
1545 struct xid2 *xid = mpcginfo->xid;
1549 int len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1551 CTCM_PR_DEBUG("Enter %s: xid=%p\n", __func__, xid);
1555 /* XID REJECTED: xid == NULL */
1556 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1557 "%s(%s): xid = NULL",
1558 CTCM_FUNTAIL, ch->id);
1562 CTCM_D3_DUMP((char *)xid, XID2_LENGTH);
1564 /*the received direction should be the opposite of ours */
1565 if (((CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? XID2_WRITE_SIDE :
1566 XID2_READ_SIDE) != xid->xid2_dlc_type) {
1568 /* XID REJECTED: r/w channel pairing mismatch */
1569 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1570 "%s(%s): r/w channel pairing mismatch",
1571 CTCM_FUNTAIL, ch->id);
1575 if (xid->xid2_dlc_type == XID2_READ_SIDE) {
1576 CTCM_PR_DEBUG("%s: grpmaxbuf:%d xid2buflen:%d\n", __func__,
1577 grp->group_max_buflen, xid->xid2_buf_len);
1579 if (grp->group_max_buflen == 0 || grp->group_max_buflen >
1580 xid->xid2_buf_len - len)
1581 grp->group_max_buflen = xid->xid2_buf_len - len;
1584 if (grp->saved_xid2 == NULL) {
1586 (struct xid2 *)skb_tail_pointer(grp->rcvd_xid_skb);
1588 skb_put_data(grp->rcvd_xid_skb, xid, XID2_LENGTH);
1589 grp->rcvd_xid_skb->data = grp->rcvd_xid_data;
1591 skb_reset_tail_pointer(grp->rcvd_xid_skb);
1592 grp->rcvd_xid_skb->len = 0;
1594 /* convert two 32 bit numbers into 1 64 bit for id compare */
1595 our_id = (__u64)priv->xid->xid2_adj_id;
1596 our_id = our_id << 32;
1597 our_id = our_id + priv->xid->xid2_sender_id;
1598 their_id = (__u64)xid->xid2_adj_id;
1599 their_id = their_id << 32;
1600 their_id = their_id + xid->xid2_sender_id;
1601 /* lower id assume the xside role */
1602 if (our_id < their_id) {
1604 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1605 "%s(%s): WE HAVE LOW ID - TAKE XSIDE",
1606 CTCM_FUNTAIL, ch->id);
1609 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1610 "%s(%s): WE HAVE HIGH ID - TAKE YSIDE",
1611 CTCM_FUNTAIL, ch->id);
1615 if (xid->xid2_flag4 != grp->saved_xid2->xid2_flag4) {
1617 /* XID REJECTED: xid flag byte4 mismatch */
1618 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1619 "%s(%s): xid flag byte4 mismatch",
1620 CTCM_FUNTAIL, ch->id);
1622 if (xid->xid2_flag2 == 0x40) {
1624 /* XID REJECTED - xid NOGOOD */
1625 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1626 "%s(%s): xid NOGOOD",
1627 CTCM_FUNTAIL, ch->id);
1629 if (xid->xid2_adj_id != grp->saved_xid2->xid2_adj_id) {
1631 /* XID REJECTED - Adjacent Station ID Mismatch */
1632 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1633 "%s(%s): Adjacent Station ID Mismatch",
1634 CTCM_FUNTAIL, ch->id);
1636 if (xid->xid2_sender_id != grp->saved_xid2->xid2_sender_id) {
1638 /* XID REJECTED - Sender Address Mismatch */
1639 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1640 "%s(%s): Sender Address Mismatch",
1641 CTCM_FUNTAIL, ch->id);
1647 "The XID used in the MPC protocol is not valid, "
1649 priv->xid->xid2_flag2 = 0x40;
1650 grp->saved_xid2->xid2_flag2 = 0x40;
1657 * MPC Group Station FSM action
1658 * CTCM_PROTO_MPC only
1660 static void mpc_action_side_xid(fsm_instance *fsm, void *arg, int side)
1662 struct channel *ch = arg;
1665 unsigned long saveflags = 0; /* avoids compiler warning with
1666 spin_unlock_irqrestore */
1668 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1669 __func__, smp_processor_id(), ch, ch->id);
1671 if (ctcm_checkalloc_buffer(ch))
1675 * skb data-buffer referencing:
1677 ch->trans_skb->data = ch->trans_skb_data;
1678 skb_reset_tail_pointer(ch->trans_skb);
1679 ch->trans_skb->len = 0;
1680 /* result of the previous 3 statements is NOT always
1681 * already set after ctcm_checkalloc_buffer
1682 * because of possible reuse of the trans_skb
1684 memset(ch->trans_skb->data, 0, 16);
1685 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1686 /* check is main purpose here: */
1687 skb_put(ch->trans_skb, TH_HEADER_LENGTH);
1688 ch->rcvd_xid = (struct xid2 *)skb_tail_pointer(ch->trans_skb);
1689 /* check is main purpose here: */
1690 skb_put(ch->trans_skb, XID2_LENGTH);
1691 ch->rcvd_xid_id = skb_tail_pointer(ch->trans_skb);
1692 /* cleanup back to startpoint */
1693 ch->trans_skb->data = ch->trans_skb_data;
1694 skb_reset_tail_pointer(ch->trans_skb);
1695 ch->trans_skb->len = 0;
1697 /* non-checking rewrite of above skb data-buffer referencing: */
1699 memset(ch->trans_skb->data, 0, 16);
1700 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1701 ch->rcvd_xid = (struct xid2 *)(ch->trans_skb_data + TH_HEADER_LENGTH);
1702 ch->rcvd_xid_id = ch->trans_skb_data + TH_HEADER_LENGTH + XID2_LENGTH;
1705 ch->ccw[8].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1706 ch->ccw[8].count = 0;
1707 ch->ccw[8].cda = 0x00;
1709 if (!(ch->xid_th && ch->xid && ch->xid_id))
1710 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_INFO,
1711 "%s(%s): xid_th=%p, xid=%p, xid_id=%p",
1712 CTCM_FUNTAIL, ch->id, ch->xid_th, ch->xid, ch->xid_id);
1714 if (side == XSIDE) {
1715 /* mpc_action_xside_xid */
1716 if (ch->xid_th == NULL)
1718 ch->ccw[9].cmd_code = CCW_CMD_WRITE;
1719 ch->ccw[9].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1720 ch->ccw[9].count = TH_HEADER_LENGTH;
1721 ch->ccw[9].cda = virt_to_phys(ch->xid_th);
1723 if (ch->xid == NULL)
1725 ch->ccw[10].cmd_code = CCW_CMD_WRITE;
1726 ch->ccw[10].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1727 ch->ccw[10].count = XID2_LENGTH;
1728 ch->ccw[10].cda = virt_to_phys(ch->xid);
1730 ch->ccw[11].cmd_code = CCW_CMD_READ;
1731 ch->ccw[11].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1732 ch->ccw[11].count = TH_HEADER_LENGTH;
1733 ch->ccw[11].cda = virt_to_phys(ch->rcvd_xid_th);
1735 ch->ccw[12].cmd_code = CCW_CMD_READ;
1736 ch->ccw[12].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1737 ch->ccw[12].count = XID2_LENGTH;
1738 ch->ccw[12].cda = virt_to_phys(ch->rcvd_xid);
1740 ch->ccw[13].cmd_code = CCW_CMD_READ;
1741 ch->ccw[13].cda = virt_to_phys(ch->rcvd_xid_id);
1743 } else { /* side == YSIDE : mpc_action_yside_xid */
1744 ch->ccw[9].cmd_code = CCW_CMD_READ;
1745 ch->ccw[9].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1746 ch->ccw[9].count = TH_HEADER_LENGTH;
1747 ch->ccw[9].cda = virt_to_phys(ch->rcvd_xid_th);
1749 ch->ccw[10].cmd_code = CCW_CMD_READ;
1750 ch->ccw[10].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1751 ch->ccw[10].count = XID2_LENGTH;
1752 ch->ccw[10].cda = virt_to_phys(ch->rcvd_xid);
1754 if (ch->xid_th == NULL)
1756 ch->ccw[11].cmd_code = CCW_CMD_WRITE;
1757 ch->ccw[11].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1758 ch->ccw[11].count = TH_HEADER_LENGTH;
1759 ch->ccw[11].cda = virt_to_phys(ch->xid_th);
1761 if (ch->xid == NULL)
1763 ch->ccw[12].cmd_code = CCW_CMD_WRITE;
1764 ch->ccw[12].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1765 ch->ccw[12].count = XID2_LENGTH;
1766 ch->ccw[12].cda = virt_to_phys(ch->xid);
1768 if (ch->xid_id == NULL)
1770 ch->ccw[13].cmd_code = CCW_CMD_WRITE;
1771 ch->ccw[13].cda = virt_to_phys(ch->xid_id);
1774 ch->ccw[13].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1775 ch->ccw[13].count = 4;
1777 ch->ccw[14].cmd_code = CCW_CMD_NOOP;
1778 ch->ccw[14].flags = CCW_FLAG_SLI;
1779 ch->ccw[14].count = 0;
1780 ch->ccw[14].cda = 0;
1782 CTCM_CCW_DUMP((char *)&ch->ccw[8], sizeof(struct ccw1) * 7);
1783 CTCM_D3_DUMP((char *)ch->xid_th, TH_HEADER_LENGTH);
1784 CTCM_D3_DUMP((char *)ch->xid, XID2_LENGTH);
1785 CTCM_D3_DUMP((char *)ch->xid_id, 4);
1788 /* Such conditional locking is a known problem for
1789 * sparse because its static undeterministic.
1790 * Warnings should be ignored here. */
1791 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1795 fsm_addtimer(&ch->timer, 5000 , CTC_EVENT_TIMER, ch);
1796 rc = ccw_device_start(ch->cdev, &ch->ccw[8],
1797 (unsigned long)ch, 0xff, 0);
1799 if (gotlock) /* see remark above about conditional locking */
1800 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1803 ctcm_ccw_check_rc(ch, rc,
1804 (side == XSIDE) ? "x-side XID" : "y-side XID");
1808 CTCM_PR_DEBUG("Exit %s: ch=0x%p id=%s\n",
1809 __func__, ch, ch->id);
1815 * MPC Group Station FSM action
1816 * CTCM_PROTO_MPC only
1818 static void mpc_action_xside_xid(fsm_instance *fsm, int event, void *arg)
1820 mpc_action_side_xid(fsm, arg, XSIDE);
1824 * MPC Group Station FSM action
1825 * CTCM_PROTO_MPC only
1827 static void mpc_action_yside_xid(fsm_instance *fsm, int event, void *arg)
1829 mpc_action_side_xid(fsm, arg, YSIDE);
1833 * MPC Group Station FSM action
1834 * CTCM_PROTO_MPC only
1836 static void mpc_action_doxid0(fsm_instance *fsm, int event, void *arg)
1838 struct channel *ch = arg;
1839 struct net_device *dev = ch->netdev;
1840 struct ctcm_priv *priv = dev->ml_priv;
1841 struct mpc_group *grp = priv->mpcg;
1843 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1844 __func__, smp_processor_id(), ch, ch->id);
1846 if (ch->xid == NULL) {
1847 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1848 "%s(%s): ch->xid == NULL",
1849 CTCM_FUNTAIL, dev->name);
1853 fsm_newstate(ch->fsm, CH_XID0_INPROGRESS);
1855 ch->xid->xid2_option = XID2_0;
1857 switch (fsm_getstate(grp->fsm)) {
1858 case MPCG_STATE_XID2INITW:
1859 case MPCG_STATE_XID2INITX:
1860 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1862 case MPCG_STATE_XID0IOWAIT:
1863 case MPCG_STATE_XID0IOWAIX:
1864 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1868 fsm_event(grp->fsm, MPCG_EVENT_DOIO, ch);
1874 * MPC Group Station FSM action
1875 * CTCM_PROTO_MPC only
1877 static void mpc_action_doxid7(fsm_instance *fsm, int event, void *arg)
1879 struct net_device *dev = arg;
1880 struct ctcm_priv *priv = dev->ml_priv;
1881 struct mpc_group *grp = NULL;
1890 for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
1891 struct channel *ch = priv->channel[direction];
1892 struct xid2 *thisxid = ch->xid;
1893 ch->xid_skb->data = ch->xid_skb_data;
1894 skb_reset_tail_pointer(ch->xid_skb);
1895 ch->xid_skb->len = 0;
1896 thisxid->xid2_option = XID2_7;
1900 if (grp->outstanding_xid7_p2 > 0) {
1901 if (grp->roll == YSIDE) {
1902 if (fsm_getstate(ch->fsm) == CH_XID7_PENDING1) {
1903 fsm_newstate(ch->fsm, CH_XID7_PENDING2);
1904 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1905 skb_put_data(ch->xid_skb, &thdummy,
1909 } else if (fsm_getstate(ch->fsm) < CH_XID7_PENDING2) {
1910 fsm_newstate(ch->fsm, CH_XID7_PENDING2);
1911 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1912 skb_put_data(ch->xid_skb, &thnorm,
1918 if (grp->roll == YSIDE) {
1919 if (fsm_getstate(ch->fsm) < CH_XID7_PENDING4) {
1920 fsm_newstate(ch->fsm, CH_XID7_PENDING4);
1921 skb_put_data(ch->xid_skb, &thnorm,
1923 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1926 } else if (fsm_getstate(ch->fsm) == CH_XID7_PENDING3) {
1927 fsm_newstate(ch->fsm, CH_XID7_PENDING4);
1928 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1929 skb_put_data(ch->xid_skb, &thdummy,
1936 fsm_event(grp->fsm, MPCG_EVENT_DOIO, ch);
1943 * MPC Group Station FSM action
1944 * CTCM_PROTO_MPC only
1946 static void mpc_action_rcvd_xid0(fsm_instance *fsm, int event, void *arg)
1949 struct mpcg_info *mpcginfo = arg;
1950 struct channel *ch = mpcginfo->ch;
1951 struct net_device *dev = ch->netdev;
1952 struct ctcm_priv *priv = dev->ml_priv;
1953 struct mpc_group *grp = priv->mpcg;
1955 CTCM_PR_DEBUG("%s: ch-id:%s xid2:%i xid7:%i xidt_p2:%i \n",
1956 __func__, ch->id, grp->outstanding_xid2,
1957 grp->outstanding_xid7, grp->outstanding_xid7_p2);
1959 if (fsm_getstate(ch->fsm) < CH_XID7_PENDING)
1960 fsm_newstate(ch->fsm, CH_XID7_PENDING);
1962 grp->outstanding_xid2--;
1963 grp->outstanding_xid7++;
1964 grp->outstanding_xid7_p2++;
1966 /* must change state before validating xid to */
1967 /* properly handle interim interrupts received*/
1968 switch (fsm_getstate(grp->fsm)) {
1969 case MPCG_STATE_XID2INITW:
1970 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITX);
1971 mpc_validate_xid(mpcginfo);
1973 case MPCG_STATE_XID0IOWAIT:
1974 fsm_newstate(grp->fsm, MPCG_STATE_XID0IOWAIX);
1975 mpc_validate_xid(mpcginfo);
1977 case MPCG_STATE_XID2INITX:
1978 if (grp->outstanding_xid2 == 0) {
1979 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITW);
1980 mpc_validate_xid(mpcginfo);
1981 fsm_event(grp->fsm, MPCG_EVENT_XID2DONE, dev);
1984 case MPCG_STATE_XID0IOWAIX:
1985 if (grp->outstanding_xid2 == 0) {
1986 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITI);
1987 mpc_validate_xid(mpcginfo);
1988 fsm_event(grp->fsm, MPCG_EVENT_XID2DONE, dev);
1993 CTCM_PR_DEBUG("ctcmpc:%s() %s xid2:%i xid7:%i xidt_p2:%i \n",
1994 __func__, ch->id, grp->outstanding_xid2,
1995 grp->outstanding_xid7, grp->outstanding_xid7_p2);
1996 CTCM_PR_DEBUG("ctcmpc:%s() %s grpstate: %s chanstate: %s \n",
1998 fsm_getstate_str(grp->fsm), fsm_getstate_str(ch->fsm));
2005 * MPC Group Station FSM action
2006 * CTCM_PROTO_MPC only
2008 static void mpc_action_rcvd_xid7(fsm_instance *fsm, int event, void *arg)
2010 struct mpcg_info *mpcginfo = arg;
2011 struct channel *ch = mpcginfo->ch;
2012 struct net_device *dev = ch->netdev;
2013 struct ctcm_priv *priv = dev->ml_priv;
2014 struct mpc_group *grp = priv->mpcg;
2016 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
2017 __func__, smp_processor_id(), ch, ch->id);
2018 CTCM_PR_DEBUG("%s: outstanding_xid7: %i, outstanding_xid7_p2: %i\n",
2019 __func__, grp->outstanding_xid7, grp->outstanding_xid7_p2);
2021 grp->outstanding_xid7--;
2022 ch->xid_skb->data = ch->xid_skb_data;
2023 skb_reset_tail_pointer(ch->xid_skb);
2024 ch->xid_skb->len = 0;
2026 switch (fsm_getstate(grp->fsm)) {
2027 case MPCG_STATE_XID7INITI:
2028 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITZ);
2029 mpc_validate_xid(mpcginfo);
2031 case MPCG_STATE_XID7INITW:
2032 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITX);
2033 mpc_validate_xid(mpcginfo);
2035 case MPCG_STATE_XID7INITZ:
2036 case MPCG_STATE_XID7INITX:
2037 if (grp->outstanding_xid7 == 0) {
2038 if (grp->outstanding_xid7_p2 > 0) {
2039 grp->outstanding_xid7 =
2040 grp->outstanding_xid7_p2;
2041 grp->outstanding_xid7_p2 = 0;
2043 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITF);
2045 mpc_validate_xid(mpcginfo);
2046 fsm_event(grp->fsm, MPCG_EVENT_XID7DONE, dev);
2049 mpc_validate_xid(mpcginfo);
2056 * mpc_action helper of an MPC Group Station FSM action
2057 * CTCM_PROTO_MPC only
2059 static int mpc_send_qllc_discontact(struct net_device *dev)
2062 struct sk_buff *skb;
2063 struct qllc *qllcptr;
2064 struct ctcm_priv *priv = dev->ml_priv;
2065 struct mpc_group *grp = priv->mpcg;
2067 CTCM_PR_DEBUG("%s: GROUP STATE: %s\n",
2068 __func__, mpcg_state_names[grp->saved_state]);
2070 switch (grp->saved_state) {
2072 * establish conn callback function is
2073 * preferred method to report failure
2075 case MPCG_STATE_XID0IOWAIT:
2076 case MPCG_STATE_XID0IOWAIX:
2077 case MPCG_STATE_XID7INITI:
2078 case MPCG_STATE_XID7INITZ:
2079 case MPCG_STATE_XID2INITW:
2080 case MPCG_STATE_XID2INITX:
2081 case MPCG_STATE_XID7INITW:
2082 case MPCG_STATE_XID7INITX:
2083 if (grp->estconnfunc) {
2084 grp->estconnfunc(grp->port_num, -1, 0);
2085 grp->estconnfunc = NULL;
2088 case MPCG_STATE_FLOWC:
2089 case MPCG_STATE_READY:
2090 grp->send_qllc_disc = 2;
2091 new_len = sizeof(struct qllc);
2092 qllcptr = kzalloc(new_len, gfp_type() | GFP_DMA);
2093 if (qllcptr == NULL) {
2094 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2095 "%s(%s): qllcptr allocation error",
2096 CTCM_FUNTAIL, dev->name);
2100 qllcptr->qllc_address = 0xcc;
2101 qllcptr->qllc_commands = 0x03;
2103 skb = __dev_alloc_skb(new_len, GFP_ATOMIC);
2106 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2107 "%s(%s): skb allocation error",
2108 CTCM_FUNTAIL, dev->name);
2109 priv->stats.rx_dropped++;
2114 skb_put_data(skb, qllcptr, new_len);
2117 if (skb_headroom(skb) < 4) {
2118 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2119 "%s(%s): skb_headroom error",
2120 CTCM_FUNTAIL, dev->name);
2121 dev_kfree_skb_any(skb);
2125 *((__u32 *)skb_push(skb, 4)) =
2126 priv->channel[CTCM_READ]->pdu_seq;
2127 priv->channel[CTCM_READ]->pdu_seq++;
2128 CTCM_PR_DBGDATA("ctcmpc: %s ToDCM_pdu_seq= %08x\n",
2129 __func__, priv->channel[CTCM_READ]->pdu_seq);
2131 /* receipt of CC03 resets anticipated sequence number on
2133 priv->channel[CTCM_READ]->pdu_seq = 0x00;
2134 skb_reset_mac_header(skb);
2136 skb->protocol = htons(ETH_P_SNAP);
2137 skb->ip_summed = CHECKSUM_UNNECESSARY;
2139 CTCM_D3_DUMP(skb->data, (sizeof(struct qllc) + 4));
2150 /* --- This is the END my friend --- */