2 * Copyright IBM Corp. 2004, 2007
3 * Authors: Belinda Thompson (belindat@us.ibm.com)
4 * Andy Richter (richtera@us.ibm.com)
5 * Peter Tiedemann (ptiedem@de.ibm.com)
9 This module exports functions to be used by CCS:
10 EXPORT_SYMBOL(ctc_mpc_alloc_channel);
11 EXPORT_SYMBOL(ctc_mpc_establish_connectivity);
12 EXPORT_SYMBOL(ctc_mpc_dealloc_ch);
13 EXPORT_SYMBOL(ctc_mpc_flow_control);
20 #define KMSG_COMPONENT "ctcm"
21 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 #include <linux/errno.h>
28 #include <linux/types.h>
29 #include <linux/interrupt.h>
30 #include <linux/timer.h>
31 #include <linux/sched.h>
33 #include <linux/signal.h>
34 #include <linux/string.h>
35 #include <linux/proc_fs.h>
38 #include <linux/if_arp.h>
39 #include <linux/tcp.h>
40 #include <linux/skbuff.h>
41 #include <linux/ctype.h>
42 #include <linux/netdevice.h>
45 #include <linux/io.h> /* instead of <asm/io.h> ok ? */
46 #include <asm/ccwdev.h>
47 #include <asm/ccwgroup.h>
48 #include <linux/bitops.h> /* instead of <asm/bitops.h> ok ? */
49 #include <linux/uaccess.h> /* instead of <asm/uaccess.h> ok ? */
50 #include <linux/wait.h>
51 #include <linux/moduleparam.h>
52 #include <asm/idals.h>
54 #include "ctcm_main.h"
56 #include "ctcm_fsms.h"
58 static const struct xid2 init_xid
= {
59 .xid2_type_id
= XID_FM2
,
71 .xid2_option
= XID2_0
,
74 .xid2_dlc_type
= XID2_READ_SIDE
,
78 .xid2_buf_len
= (MPC_BUFSIZE_DEFAULT
- 35),
81 static const struct th_header thnorm
= {
83 .th_ch_flag
= TH_IS_XID
,
84 .th_blk_flag
= TH_DATA_IS_XID
,
86 .th_seq_num
= 0x00000000,
89 static const struct th_header thdummy
= {
92 .th_blk_flag
= TH_DATA_IS_XID
,
94 .th_seq_num
= 0x00000000,
98 * Definition of one MPC group
102 * Compatibility macros for busy handling
103 * of network devices.
106 static void ctcmpc_unpack_skb(struct channel
*ch
, struct sk_buff
*pskb
);
109 * MPC Group state machine actions (static prototypes)
111 static void mpc_action_nop(fsm_instance
*fsm
, int event
, void *arg
);
112 static void mpc_action_go_ready(fsm_instance
*fsm
, int event
, void *arg
);
113 static void mpc_action_go_inop(fsm_instance
*fi
, int event
, void *arg
);
114 static void mpc_action_timeout(fsm_instance
*fi
, int event
, void *arg
);
115 static int mpc_validate_xid(struct mpcg_info
*mpcginfo
);
116 static void mpc_action_yside_xid(fsm_instance
*fsm
, int event
, void *arg
);
117 static void mpc_action_doxid0(fsm_instance
*fsm
, int event
, void *arg
);
118 static void mpc_action_doxid7(fsm_instance
*fsm
, int event
, void *arg
);
119 static void mpc_action_xside_xid(fsm_instance
*fsm
, int event
, void *arg
);
120 static void mpc_action_rcvd_xid0(fsm_instance
*fsm
, int event
, void *arg
);
121 static void mpc_action_rcvd_xid7(fsm_instance
*fsm
, int event
, void *arg
);
124 /*-------------------------------------------------------------------*
125 * Dump buffer format *
127 *--------------------------------------------------------------------*/
128 void ctcmpc_dumpit(char *buf
, int len
)
130 __u32 ct
, sw
, rm
, dup
;
132 char tbuf
[82], tdup
[82];
139 char bhex
[82], duphex
[82];
148 for (ct
= 0; ct
< len
; ct
++, ptr
++, rptr
++) {
151 sprintf(addr
, "%16.16llx", (__u64
)rptr
);
153 sprintf(addr
, "%8.8X", (__u32
)rptr
);
156 sprintf(boff
, "%4.4X", (__u32
)ct
);
160 if ((sw
== 4) || (sw
== 12))
166 sprintf(tbuf
, "%2.2llX", (__u64
)*ptr
);
168 sprintf(tbuf
, "%2.2X", (__u32
)*ptr
);
173 if ((0 != isprint(*ptr
)) && (*ptr
>= 0x20))
183 if ((strcmp(duphex
, bhex
)) != 0) {
186 "Duplicate as above to %s", addr
);
187 ctcm_pr_debug(" --- %s ---\n",
190 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
191 addr
, boff
, bhex
, basc
);
193 strcpy(duphex
, bhex
);
202 for ( ; rm
> 0; rm
--, sw
++) {
203 if ((sw
== 4) || (sw
== 12))
211 sprintf(tdup
, "Duplicate as above to %s", addr
);
212 ctcm_pr_debug(" --- %s ---\n", tdup
);
214 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
215 addr
, boff
, bhex
, basc
);
218 sprintf(tdup
, "Duplicate as above to %s", addr
);
219 ctcm_pr_debug(" --- %s ---\n", tdup
);
222 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
223 addr
, boff
, bhex
, basc
);
229 } /* end of ctcmpc_dumpit */
234 * Dump header and first 16 bytes of an sk_buff for debugging purposes.
236 * skb The sk_buff to dump.
237 * offset Offset relative to skb-data, where to start the dump.
239 void ctcmpc_dump_skb(struct sk_buff
*skb
, int offset
)
242 struct th_header
*header
;
251 header
= (struct th_header
*)p
;
253 ctcm_pr_debug("dump:\n");
254 ctcm_pr_debug("skb len=%d \n", skb
->len
);
256 switch (header
->th_ch_flag
) {
261 if ((header
->th_blk_flag
== TH_DATA_IS_XID
) &&
262 (header
->th_is_xid
== 0x01))
272 pheader
= (struct pdu
*)p
;
273 ctcm_pr_debug("pdu->offset: %d hex: %04x\n",
274 pheader
->pdu_offset
, pheader
->pdu_offset
);
275 ctcm_pr_debug("pdu->flag : %02x\n", pheader
->pdu_flag
);
276 ctcm_pr_debug("pdu->proto : %02x\n", pheader
->pdu_proto
);
277 ctcm_pr_debug("pdu->seq : %02x\n", pheader
->pdu_seq
);
281 ctcm_pr_debug("th->seg : %02x\n", header
->th_seg
);
282 ctcm_pr_debug("th->ch : %02x\n", header
->th_ch_flag
);
283 ctcm_pr_debug("th->blk_flag: %02x\n", header
->th_blk_flag
);
284 ctcm_pr_debug("th->type : %s\n",
285 (header
->th_is_xid
) ? "DATA" : "XID");
286 ctcm_pr_debug("th->seqnum : %04x\n", header
->th_seq_num
);
292 ctcm_pr_debug("data: ");
293 for (i
= 0; i
< bl
; i
++)
294 ctcm_pr_debug("%02x%s", *p
++, (i
% 16) ? " " : "\n");
299 static struct net_device
*ctcmpc_get_dev(int port_num
)
302 struct net_device
*dev
;
303 struct ctcm_priv
*priv
;
305 sprintf(device
, "%s%i", MPC_DEVICE_NAME
, port_num
);
307 dev
= __dev_get_by_name(&init_net
, device
);
310 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
311 "%s: Device not found by name: %s",
312 CTCM_FUNTAIL
, device
);
317 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
318 "%s(%s): dev->ml_priv is NULL",
319 CTCM_FUNTAIL
, device
);
322 if (priv
->mpcg
== NULL
) {
323 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
324 "%s(%s): priv->mpcg is NULL",
325 CTCM_FUNTAIL
, device
);
332 * ctc_mpc_alloc_channel
333 * (exported interface)
335 * Device Initialization :
336 * ACTPATH driven IO operations
338 int ctc_mpc_alloc_channel(int port_num
, void (*callback
)(int, int))
340 struct net_device
*dev
;
341 struct mpc_group
*grp
;
342 struct ctcm_priv
*priv
;
344 dev
= ctcmpc_get_dev(port_num
);
350 grp
->allochanfunc
= callback
;
351 grp
->port_num
= port_num
;
352 grp
->port_persist
= 1;
354 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_INFO
,
356 CTCM_FUNTAIL
, dev
->name
, fsm_getstate_str(grp
->fsm
));
358 switch (fsm_getstate(grp
->fsm
)) {
359 case MPCG_STATE_INOP
:
360 /* Group is in the process of terminating */
361 grp
->alloc_called
= 1;
363 case MPCG_STATE_RESET
:
364 /* MPC Group will transition to state */
365 /* MPCG_STATE_XID2INITW iff the minimum number */
366 /* of 1 read and 1 write channel have successfully*/
368 /*fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);*/
370 grp
->send_qllc_disc
= 1;
371 case MPCG_STATE_XID0IOWAIT
:
372 fsm_deltimer(&grp
->timer
);
373 grp
->outstanding_xid2
= 0;
374 grp
->outstanding_xid7
= 0;
375 grp
->outstanding_xid7_p2
= 0;
376 grp
->saved_xid2
= NULL
;
379 fsm_event(priv
->fsm
, DEV_EVENT_START
, dev
);
381 case MPCG_STATE_READY
:
382 /* XID exchanges completed after PORT was activated */
383 /* Link station already active */
384 /* Maybe timing issue...retry callback */
385 grp
->allocchan_callback_retries
++;
386 if (grp
->allocchan_callback_retries
< 4) {
387 if (grp
->allochanfunc
)
388 grp
->allochanfunc(grp
->port_num
,
389 grp
->group_max_buflen
);
391 /* there are problems...bail out */
392 /* there may be a state mismatch so restart */
393 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
394 grp
->allocchan_callback_retries
= 0;
401 EXPORT_SYMBOL(ctc_mpc_alloc_channel
);
404 * ctc_mpc_establish_connectivity
405 * (exported interface)
407 void ctc_mpc_establish_connectivity(int port_num
,
408 void (*callback
)(int, int, int))
410 struct net_device
*dev
;
411 struct mpc_group
*grp
;
412 struct ctcm_priv
*priv
;
413 struct channel
*rch
, *wch
;
415 dev
= ctcmpc_get_dev(port_num
);
420 rch
= priv
->channel
[CTCM_READ
];
421 wch
= priv
->channel
[CTCM_WRITE
];
423 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_INFO
,
425 CTCM_FUNTAIL
, dev
->name
, fsm_getstate_str(grp
->fsm
));
427 grp
->estconnfunc
= callback
;
428 grp
->port_num
= port_num
;
430 switch (fsm_getstate(grp
->fsm
)) {
431 case MPCG_STATE_READY
:
432 /* XID exchanges completed after PORT was activated */
433 /* Link station already active */
434 /* Maybe timing issue...retry callback */
435 fsm_deltimer(&grp
->timer
);
436 grp
->estconn_callback_retries
++;
437 if (grp
->estconn_callback_retries
< 4) {
438 if (grp
->estconnfunc
) {
439 grp
->estconnfunc(grp
->port_num
, 0,
440 grp
->group_max_buflen
);
441 grp
->estconnfunc
= NULL
;
444 /* there are problems...bail out */
445 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
446 grp
->estconn_callback_retries
= 0;
449 case MPCG_STATE_INOP
:
450 case MPCG_STATE_RESET
:
451 /* MPC Group is not ready to start XID - min num of */
452 /* 1 read and 1 write channel have not been acquired*/
454 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
455 "%s(%s): REJECTED - inactive channels",
456 CTCM_FUNTAIL
, dev
->name
);
457 if (grp
->estconnfunc
) {
458 grp
->estconnfunc(grp
->port_num
, -1, 0);
459 grp
->estconnfunc
= NULL
;
462 case MPCG_STATE_XID2INITW
:
463 /* alloc channel was called but no XID exchange */
464 /* has occurred. initiate xside XID exchange */
465 /* make sure yside XID0 processing has not started */
467 if ((fsm_getstate(rch
->fsm
) > CH_XID0_PENDING
) ||
468 (fsm_getstate(wch
->fsm
) > CH_XID0_PENDING
)) {
469 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
470 "%s(%s): ABORT - PASSIVE XID",
471 CTCM_FUNTAIL
, dev
->name
);
474 grp
->send_qllc_disc
= 1;
475 fsm_newstate(grp
->fsm
, MPCG_STATE_XID0IOWAIT
);
476 fsm_deltimer(&grp
->timer
);
477 fsm_addtimer(&grp
->timer
, MPC_XID_TIMEOUT_VALUE
,
478 MPCG_EVENT_TIMER
, dev
);
479 grp
->outstanding_xid7
= 0;
480 grp
->outstanding_xid7_p2
= 0;
481 grp
->saved_xid2
= NULL
;
482 if ((rch
->in_mpcgroup
) &&
483 (fsm_getstate(rch
->fsm
) == CH_XID0_PENDING
))
484 fsm_event(grp
->fsm
, MPCG_EVENT_XID0DO
, rch
);
486 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
487 "%s(%s): RX-%s not ready for ACTIVE XID0",
488 CTCM_FUNTAIL
, dev
->name
, rch
->id
);
489 if (grp
->estconnfunc
) {
490 grp
->estconnfunc(grp
->port_num
, -1, 0);
491 grp
->estconnfunc
= NULL
;
493 fsm_deltimer(&grp
->timer
);
496 if ((wch
->in_mpcgroup
) &&
497 (fsm_getstate(wch
->fsm
) == CH_XID0_PENDING
))
498 fsm_event(grp
->fsm
, MPCG_EVENT_XID0DO
, wch
);
500 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
501 "%s(%s): WX-%s not ready for ACTIVE XID0",
502 CTCM_FUNTAIL
, dev
->name
, wch
->id
);
503 if (grp
->estconnfunc
) {
504 grp
->estconnfunc(grp
->port_num
, -1, 0);
505 grp
->estconnfunc
= NULL
;
507 fsm_deltimer(&grp
->timer
);
511 case MPCG_STATE_XID0IOWAIT
:
512 /* already in active XID negotiations */
518 CTCM_PR_DEBUG("Exit %s()\n", __func__
);
521 EXPORT_SYMBOL(ctc_mpc_establish_connectivity
);
525 * (exported interface)
527 void ctc_mpc_dealloc_ch(int port_num
)
529 struct net_device
*dev
;
530 struct ctcm_priv
*priv
;
531 struct mpc_group
*grp
;
533 dev
= ctcmpc_get_dev(port_num
);
539 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_DEBUG
,
540 "%s: %s: refcount = %d\n",
541 CTCM_FUNTAIL
, dev
->name
, netdev_refcnt_read(dev
));
543 fsm_deltimer(&priv
->restart_timer
);
544 grp
->channels_terminating
= 0;
545 fsm_deltimer(&grp
->timer
);
546 grp
->allochanfunc
= NULL
;
547 grp
->estconnfunc
= NULL
;
548 grp
->port_persist
= 0;
549 grp
->send_qllc_disc
= 0;
550 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
555 EXPORT_SYMBOL(ctc_mpc_dealloc_ch
);
558 * ctc_mpc_flow_control
559 * (exported interface)
561 void ctc_mpc_flow_control(int port_num
, int flowc
)
563 struct ctcm_priv
*priv
;
564 struct mpc_group
*grp
;
565 struct net_device
*dev
;
569 dev
= ctcmpc_get_dev(port_num
);
575 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_DEBUG
,
576 "%s: %s: flowc = %d",
577 CTCM_FUNTAIL
, dev
->name
, flowc
);
579 rch
= priv
->channel
[CTCM_READ
];
581 mpcg_state
= fsm_getstate(grp
->fsm
);
584 if (mpcg_state
== MPCG_STATE_FLOWC
)
586 if (mpcg_state
== MPCG_STATE_READY
) {
587 if (grp
->flow_off_called
== 1)
588 grp
->flow_off_called
= 0;
590 fsm_newstate(grp
->fsm
, MPCG_STATE_FLOWC
);
595 if (mpcg_state
== MPCG_STATE_FLOWC
) {
596 fsm_newstate(grp
->fsm
, MPCG_STATE_READY
);
597 /* ensure any data that has accumulated */
598 /* on the io_queue will now be sen t */
599 tasklet_schedule(&rch
->ch_tasklet
);
601 /* possible race condition */
602 if (mpcg_state
== MPCG_STATE_READY
) {
603 grp
->flow_off_called
= 1;
610 EXPORT_SYMBOL(ctc_mpc_flow_control
);
612 static int mpc_send_qllc_discontact(struct net_device
*);
615 * helper function of ctcmpc_unpack_skb
617 static void mpc_rcvd_sweep_resp(struct mpcg_info
*mpcginfo
)
619 struct channel
*rch
= mpcginfo
->ch
;
620 struct net_device
*dev
= rch
->netdev
;
621 struct ctcm_priv
*priv
= dev
->ml_priv
;
622 struct mpc_group
*grp
= priv
->mpcg
;
623 struct channel
*ch
= priv
->channel
[CTCM_WRITE
];
625 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__
, ch
, ch
->id
);
626 CTCM_D3_DUMP((char *)mpcginfo
->sweep
, TH_SWEEP_LENGTH
);
628 grp
->sweep_rsp_pend_num
--;
630 if ((grp
->sweep_req_pend_num
== 0) &&
631 (grp
->sweep_rsp_pend_num
== 0)) {
632 fsm_deltimer(&ch
->sweep_timer
);
634 rch
->th_seq_num
= 0x00;
635 ch
->th_seq_num
= 0x00;
636 ctcm_clear_busy_do(dev
);
646 * helper function of mpc_rcvd_sweep_req
647 * which is a helper of ctcmpc_unpack_skb
649 static void ctcmpc_send_sweep_resp(struct channel
*rch
)
651 struct net_device
*dev
= rch
->netdev
;
652 struct ctcm_priv
*priv
= dev
->ml_priv
;
653 struct mpc_group
*grp
= priv
->mpcg
;
654 struct th_sweep
*header
;
655 struct sk_buff
*sweep_skb
;
656 struct channel
*ch
= priv
->channel
[CTCM_WRITE
];
658 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__
, rch
, rch
->id
);
660 sweep_skb
= __dev_alloc_skb(MPC_BUFSIZE_DEFAULT
, GFP_ATOMIC
| GFP_DMA
);
661 if (sweep_skb
== NULL
) {
662 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
663 "%s(%s): sweep_skb allocation ERROR\n",
664 CTCM_FUNTAIL
, rch
->id
);
668 header
= kmalloc(sizeof(struct th_sweep
), gfp_type());
671 dev_kfree_skb_any(sweep_skb
);
675 header
->th
.th_seg
= 0x00 ;
676 header
->th
.th_ch_flag
= TH_SWEEP_RESP
;
677 header
->th
.th_blk_flag
= 0x00;
678 header
->th
.th_is_xid
= 0x00;
679 header
->th
.th_seq_num
= 0x00;
680 header
->sw
.th_last_seq
= ch
->th_seq_num
;
682 memcpy(skb_put(sweep_skb
, TH_SWEEP_LENGTH
), header
, TH_SWEEP_LENGTH
);
686 dev
->trans_start
= jiffies
;
687 skb_queue_tail(&ch
->sweep_queue
, sweep_skb
);
689 fsm_addtimer(&ch
->sweep_timer
, 100, CTC_EVENT_RSWEEP_TIMER
, ch
);
695 ctcm_clear_busy_do(dev
);
696 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
702 * helper function of ctcmpc_unpack_skb
704 static void mpc_rcvd_sweep_req(struct mpcg_info
*mpcginfo
)
706 struct channel
*rch
= mpcginfo
->ch
;
707 struct net_device
*dev
= rch
->netdev
;
708 struct ctcm_priv
*priv
= dev
->ml_priv
;
709 struct mpc_group
*grp
= priv
->mpcg
;
710 struct channel
*ch
= priv
->channel
[CTCM_WRITE
];
713 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_DEBUG
,
714 " %s(): ch=0x%p id=%s\n", __func__
, ch
, ch
->id
);
716 if (grp
->in_sweep
== 0) {
718 ctcm_test_and_set_busy(dev
);
719 grp
->sweep_req_pend_num
= grp
->active_channels
[CTCM_READ
];
720 grp
->sweep_rsp_pend_num
= grp
->active_channels
[CTCM_READ
];
723 CTCM_D3_DUMP((char *)mpcginfo
->sweep
, TH_SWEEP_LENGTH
);
725 grp
->sweep_req_pend_num
--;
726 ctcmpc_send_sweep_resp(ch
);
732 * MPC Group Station FSM definitions
734 static const char *mpcg_event_names
[] = {
735 [MPCG_EVENT_INOP
] = "INOP Condition",
736 [MPCG_EVENT_DISCONC
] = "Discontact Received",
737 [MPCG_EVENT_XID0DO
] = "Channel Active - Start XID",
738 [MPCG_EVENT_XID2
] = "XID2 Received",
739 [MPCG_EVENT_XID2DONE
] = "XID0 Complete",
740 [MPCG_EVENT_XID7DONE
] = "XID7 Complete",
741 [MPCG_EVENT_TIMER
] = "XID Setup Timer",
742 [MPCG_EVENT_DOIO
] = "XID DoIO",
745 static const char *mpcg_state_names
[] = {
746 [MPCG_STATE_RESET
] = "Reset",
747 [MPCG_STATE_INOP
] = "INOP",
748 [MPCG_STATE_XID2INITW
] = "Passive XID- XID0 Pending Start",
749 [MPCG_STATE_XID2INITX
] = "Passive XID- XID0 Pending Complete",
750 [MPCG_STATE_XID7INITW
] = "Passive XID- XID7 Pending P1 Start",
751 [MPCG_STATE_XID7INITX
] = "Passive XID- XID7 Pending P2 Complete",
752 [MPCG_STATE_XID0IOWAIT
] = "Active XID- XID0 Pending Start",
753 [MPCG_STATE_XID0IOWAIX
] = "Active XID- XID0 Pending Complete",
754 [MPCG_STATE_XID7INITI
] = "Active XID- XID7 Pending Start",
755 [MPCG_STATE_XID7INITZ
] = "Active XID- XID7 Pending Complete ",
756 [MPCG_STATE_XID7INITF
] = "XID - XID7 Complete ",
757 [MPCG_STATE_FLOWC
] = "FLOW CONTROL ON",
758 [MPCG_STATE_READY
] = "READY",
762 * The MPC Group Station FSM
765 static const fsm_node mpcg_fsm
[] = {
766 { MPCG_STATE_RESET
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
767 { MPCG_STATE_INOP
, MPCG_EVENT_INOP
, mpc_action_nop
},
768 { MPCG_STATE_FLOWC
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
770 { MPCG_STATE_READY
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
771 { MPCG_STATE_READY
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
773 { MPCG_STATE_XID2INITW
, MPCG_EVENT_XID0DO
, mpc_action_doxid0
},
774 { MPCG_STATE_XID2INITW
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid0
},
775 { MPCG_STATE_XID2INITW
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
776 { MPCG_STATE_XID2INITW
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
777 { MPCG_STATE_XID2INITW
, MPCG_EVENT_DOIO
, mpc_action_yside_xid
},
779 { MPCG_STATE_XID2INITX
, MPCG_EVENT_XID0DO
, mpc_action_doxid0
},
780 { MPCG_STATE_XID2INITX
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid0
},
781 { MPCG_STATE_XID2INITX
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
782 { MPCG_STATE_XID2INITX
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
783 { MPCG_STATE_XID2INITX
, MPCG_EVENT_DOIO
, mpc_action_yside_xid
},
785 { MPCG_STATE_XID7INITW
, MPCG_EVENT_XID2DONE
, mpc_action_doxid7
},
786 { MPCG_STATE_XID7INITW
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
787 { MPCG_STATE_XID7INITW
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid7
},
788 { MPCG_STATE_XID7INITW
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
789 { MPCG_STATE_XID7INITW
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
790 { MPCG_STATE_XID7INITW
, MPCG_EVENT_XID7DONE
, mpc_action_doxid7
},
791 { MPCG_STATE_XID7INITW
, MPCG_EVENT_DOIO
, mpc_action_yside_xid
},
793 { MPCG_STATE_XID7INITX
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
794 { MPCG_STATE_XID7INITX
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid7
},
795 { MPCG_STATE_XID7INITX
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
796 { MPCG_STATE_XID7INITX
, MPCG_EVENT_XID7DONE
, mpc_action_doxid7
},
797 { MPCG_STATE_XID7INITX
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
798 { MPCG_STATE_XID7INITX
, MPCG_EVENT_DOIO
, mpc_action_yside_xid
},
800 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_XID0DO
, mpc_action_doxid0
},
801 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
802 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid0
},
803 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
804 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
805 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_DOIO
, mpc_action_xside_xid
},
807 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_XID0DO
, mpc_action_doxid0
},
808 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
809 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid0
},
810 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
811 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
812 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_DOIO
, mpc_action_xside_xid
},
814 { MPCG_STATE_XID7INITI
, MPCG_EVENT_XID2DONE
, mpc_action_doxid7
},
815 { MPCG_STATE_XID7INITI
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid7
},
816 { MPCG_STATE_XID7INITI
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
817 { MPCG_STATE_XID7INITI
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
818 { MPCG_STATE_XID7INITI
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
819 { MPCG_STATE_XID7INITI
, MPCG_EVENT_XID7DONE
, mpc_action_doxid7
},
820 { MPCG_STATE_XID7INITI
, MPCG_EVENT_DOIO
, mpc_action_xside_xid
},
822 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid7
},
823 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_XID7DONE
, mpc_action_doxid7
},
824 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
825 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
826 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
827 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_DOIO
, mpc_action_xside_xid
},
829 { MPCG_STATE_XID7INITF
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
830 { MPCG_STATE_XID7INITF
, MPCG_EVENT_XID7DONE
, mpc_action_go_ready
},
833 static int mpcg_fsm_len
= ARRAY_SIZE(mpcg_fsm
);
836 * MPC Group Station FSM action
837 * CTCM_PROTO_MPC only
839 static void mpc_action_go_ready(fsm_instance
*fsm
, int event
, void *arg
)
841 struct net_device
*dev
= arg
;
842 struct ctcm_priv
*priv
= dev
->ml_priv
;
843 struct mpc_group
*grp
= priv
->mpcg
;
846 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
847 "%s(%s): No MPC group",
848 CTCM_FUNTAIL
, dev
->name
);
852 fsm_deltimer(&grp
->timer
);
854 if (grp
->saved_xid2
->xid2_flag2
== 0x40) {
855 priv
->xid
->xid2_flag2
= 0x00;
856 if (grp
->estconnfunc
) {
857 grp
->estconnfunc(grp
->port_num
, 1,
858 grp
->group_max_buflen
);
859 grp
->estconnfunc
= NULL
;
860 } else if (grp
->allochanfunc
)
861 grp
->send_qllc_disc
= 1;
863 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
864 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
866 CTCM_FUNTAIL
, dev
->name
);
870 grp
->port_persist
= 1;
871 grp
->out_of_sequence
= 0;
872 grp
->estconn_called
= 0;
874 tasklet_hi_schedule(&grp
->mpc_tasklet2
);
880 * helper of ctcm_init_netdevice
881 * CTCM_PROTO_MPC only
883 void mpc_group_ready(unsigned long adev
)
885 struct net_device
*dev
= (struct net_device
*)adev
;
886 struct ctcm_priv
*priv
= dev
->ml_priv
;
887 struct mpc_group
*grp
= priv
->mpcg
;
888 struct channel
*ch
= NULL
;
891 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
892 "%s(%s): No MPC group",
893 CTCM_FUNTAIL
, dev
->name
);
897 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_NOTICE
,
898 "%s: %s: GROUP TRANSITIONED TO READY, maxbuf = %d\n",
899 CTCM_FUNTAIL
, dev
->name
, grp
->group_max_buflen
);
901 fsm_newstate(grp
->fsm
, MPCG_STATE_READY
);
903 /* Put up a read on the channel */
904 ch
= priv
->channel
[CTCM_READ
];
906 CTCM_PR_DBGDATA("ctcmpc: %s() ToDCM_pdu_seq= %08x\n" ,
907 __func__
, ch
->pdu_seq
);
909 ctcmpc_chx_rxidle(ch
->fsm
, CTC_EVENT_START
, ch
);
910 /* Put the write channel in idle state */
911 ch
= priv
->channel
[CTCM_WRITE
];
912 if (ch
->collect_len
> 0) {
913 spin_lock(&ch
->collect_lock
);
914 ctcm_purge_skb_queue(&ch
->collect_queue
);
916 spin_unlock(&ch
->collect_lock
);
918 ctcm_chx_txidle(ch
->fsm
, CTC_EVENT_START
, ch
);
919 ctcm_clear_busy(dev
);
921 if (grp
->estconnfunc
) {
922 grp
->estconnfunc(grp
->port_num
, 0,
923 grp
->group_max_buflen
);
924 grp
->estconnfunc
= NULL
;
925 } else if (grp
->allochanfunc
)
926 grp
->allochanfunc(grp
->port_num
, grp
->group_max_buflen
);
928 grp
->send_qllc_disc
= 1;
929 grp
->changed_side
= 0;
936 * Increment the MPC Group Active Channel Counts
937 * helper of dev_action (called from channel fsm)
939 void mpc_channel_action(struct channel
*ch
, int direction
, int action
)
941 struct net_device
*dev
= ch
->netdev
;
942 struct ctcm_priv
*priv
= dev
->ml_priv
;
943 struct mpc_group
*grp
= priv
->mpcg
;
946 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
947 "%s(%s): No MPC group",
948 CTCM_FUNTAIL
, dev
->name
);
952 CTCM_PR_DEBUG("enter %s: ch=0x%p id=%s\n", __func__
, ch
, ch
->id
);
954 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
955 "%s: %i / Grp:%s total_channels=%i, active_channels: "
956 "read=%i, write=%i\n", __func__
, action
,
957 fsm_getstate_str(grp
->fsm
), grp
->num_channel_paths
,
958 grp
->active_channels
[CTCM_READ
],
959 grp
->active_channels
[CTCM_WRITE
]);
961 if ((action
== MPC_CHANNEL_ADD
) && (ch
->in_mpcgroup
== 0)) {
962 grp
->num_channel_paths
++;
963 grp
->active_channels
[direction
]++;
964 grp
->outstanding_xid2
++;
967 if (ch
->xid_skb
!= NULL
)
968 dev_kfree_skb_any(ch
->xid_skb
);
970 ch
->xid_skb
= __dev_alloc_skb(MPC_BUFSIZE_DEFAULT
,
971 GFP_ATOMIC
| GFP_DMA
);
972 if (ch
->xid_skb
== NULL
) {
973 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
974 "%s(%s): Couldn't alloc ch xid_skb\n",
975 CTCM_FUNTAIL
, dev
->name
);
976 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
979 ch
->xid_skb_data
= ch
->xid_skb
->data
;
980 ch
->xid_th
= (struct th_header
*)ch
->xid_skb
->data
;
981 skb_put(ch
->xid_skb
, TH_HEADER_LENGTH
);
982 ch
->xid
= (struct xid2
*)skb_tail_pointer(ch
->xid_skb
);
983 skb_put(ch
->xid_skb
, XID2_LENGTH
);
984 ch
->xid_id
= skb_tail_pointer(ch
->xid_skb
);
985 ch
->xid_skb
->data
= ch
->xid_skb_data
;
986 skb_reset_tail_pointer(ch
->xid_skb
);
987 ch
->xid_skb
->len
= 0;
989 memcpy(skb_put(ch
->xid_skb
, grp
->xid_skb
->len
),
993 ch
->xid
->xid2_dlc_type
=
994 ((CHANNEL_DIRECTION(ch
->flags
) == CTCM_READ
)
995 ? XID2_READ_SIDE
: XID2_WRITE_SIDE
);
997 if (CHANNEL_DIRECTION(ch
->flags
) == CTCM_WRITE
)
998 ch
->xid
->xid2_buf_len
= 0x00;
1000 ch
->xid_skb
->data
= ch
->xid_skb_data
;
1001 skb_reset_tail_pointer(ch
->xid_skb
);
1002 ch
->xid_skb
->len
= 0;
1004 fsm_newstate(ch
->fsm
, CH_XID0_PENDING
);
1006 if ((grp
->active_channels
[CTCM_READ
] > 0) &&
1007 (grp
->active_channels
[CTCM_WRITE
] > 0) &&
1008 (fsm_getstate(grp
->fsm
) < MPCG_STATE_XID2INITW
)) {
1009 fsm_newstate(grp
->fsm
, MPCG_STATE_XID2INITW
);
1010 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_NOTICE
,
1011 "%s: %s: MPC GROUP CHANNELS ACTIVE\n",
1012 __func__
, dev
->name
);
1014 } else if ((action
== MPC_CHANNEL_REMOVE
) &&
1015 (ch
->in_mpcgroup
== 1)) {
1016 ch
->in_mpcgroup
= 0;
1017 grp
->num_channel_paths
--;
1018 grp
->active_channels
[direction
]--;
1020 if (ch
->xid_skb
!= NULL
)
1021 dev_kfree_skb_any(ch
->xid_skb
);
1024 if (grp
->channels_terminating
)
1027 if (((grp
->active_channels
[CTCM_READ
] == 0) &&
1028 (grp
->active_channels
[CTCM_WRITE
] > 0))
1029 || ((grp
->active_channels
[CTCM_WRITE
] == 0) &&
1030 (grp
->active_channels
[CTCM_READ
] > 0)))
1031 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1034 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_DEBUG
,
1035 "exit %s: %i / Grp:%s total_channels=%i, active_channels: "
1036 "read=%i, write=%i\n", __func__
, action
,
1037 fsm_getstate_str(grp
->fsm
), grp
->num_channel_paths
,
1038 grp
->active_channels
[CTCM_READ
],
1039 grp
->active_channels
[CTCM_WRITE
]);
1041 CTCM_PR_DEBUG("exit %s: ch=0x%p id=%s\n", __func__
, ch
, ch
->id
);
1045 * Unpack a just received skb and hand it over to
1047 * special MPC version of unpack_skb.
1049 * ch The channel where this skb has been received.
1050 * pskb The received skb.
1052 static void ctcmpc_unpack_skb(struct channel
*ch
, struct sk_buff
*pskb
)
1054 struct net_device
*dev
= ch
->netdev
;
1055 struct ctcm_priv
*priv
= dev
->ml_priv
;
1056 struct mpc_group
*grp
= priv
->mpcg
;
1057 struct pdu
*curr_pdu
;
1058 struct mpcg_info
*mpcginfo
;
1059 struct th_header
*header
= NULL
;
1060 struct th_sweep
*sweep
= NULL
;
1061 int pdu_last_seen
= 0;
1063 struct sk_buff
*skb
;
1067 CTCM_PR_DEBUG("ctcmpc enter: %s() %s cp:%i ch:%s\n",
1068 __func__
, dev
->name
, smp_processor_id(), ch
->id
);
1070 header
= (struct th_header
*)pskb
->data
;
1071 if ((header
->th_seg
== 0) &&
1072 (header
->th_ch_flag
== 0) &&
1073 (header
->th_blk_flag
== 0) &&
1074 (header
->th_seq_num
== 0))
1075 /* nothing for us */ goto done
;
1077 CTCM_PR_DBGDATA("%s: th_header\n", __func__
);
1078 CTCM_D3_DUMP((char *)header
, TH_HEADER_LENGTH
);
1079 CTCM_PR_DBGDATA("%s: pskb len: %04x \n", __func__
, pskb
->len
);
1082 pskb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1083 skb_pull(pskb
, TH_HEADER_LENGTH
);
1085 if (likely(header
->th_ch_flag
== TH_HAS_PDU
)) {
1086 CTCM_PR_DBGDATA("%s: came into th_has_pdu\n", __func__
);
1087 if ((fsm_getstate(grp
->fsm
) == MPCG_STATE_FLOWC
) ||
1088 ((fsm_getstate(grp
->fsm
) == MPCG_STATE_READY
) &&
1089 (header
->th_seq_num
!= ch
->th_seq_num
+ 1) &&
1090 (ch
->th_seq_num
!= 0))) {
1091 /* This is NOT the next segment *
1092 * we are not the correct race winner *
1093 * go away and let someone else win *
1094 * BUT..this only applies if xid negot *
1097 grp
->out_of_sequence
+= 1;
1098 __skb_push(pskb
, TH_HEADER_LENGTH
);
1099 skb_queue_tail(&ch
->io_queue
, pskb
);
1100 CTCM_PR_DBGDATA("%s: th_seq_num expect:%08x "
1101 "got:%08x\n", __func__
,
1102 ch
->th_seq_num
+ 1, header
->th_seq_num
);
1106 grp
->out_of_sequence
= 0;
1107 ch
->th_seq_num
= header
->th_seq_num
;
1109 CTCM_PR_DBGDATA("ctcmpc: %s() FromVTAM_th_seq=%08x\n",
1110 __func__
, ch
->th_seq_num
);
1112 if (unlikely(fsm_getstate(grp
->fsm
) != MPCG_STATE_READY
))
1114 while ((pskb
->len
> 0) && !pdu_last_seen
) {
1115 curr_pdu
= (struct pdu
*)pskb
->data
;
1117 CTCM_PR_DBGDATA("%s: pdu_header\n", __func__
);
1118 CTCM_D3_DUMP((char *)pskb
->data
, PDU_HEADER_LENGTH
);
1119 CTCM_PR_DBGDATA("%s: pskb len: %04x \n",
1120 __func__
, pskb
->len
);
1122 skb_pull(pskb
, PDU_HEADER_LENGTH
);
1124 if (curr_pdu
->pdu_flag
& PDU_LAST
)
1126 if (curr_pdu
->pdu_flag
& PDU_CNTL
)
1127 pskb
->protocol
= htons(ETH_P_SNAP
);
1129 pskb
->protocol
= htons(ETH_P_SNA_DIX
);
1131 if ((pskb
->len
<= 0) || (pskb
->len
> ch
->max_bufsize
)) {
1132 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1133 "%s(%s): Dropping packet with "
1135 CTCM_FUNTAIL
, dev
->name
, pskb
->len
);
1137 priv
->stats
.rx_dropped
++;
1138 priv
->stats
.rx_length_errors
++;
1141 skb_reset_mac_header(pskb
);
1142 new_len
= curr_pdu
->pdu_offset
;
1143 CTCM_PR_DBGDATA("%s: new_len: %04x \n",
1145 if ((new_len
== 0) || (new_len
> pskb
->len
)) {
1146 /* should never happen */
1147 /* pskb len must be hosed...bail out */
1148 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1149 "%s(%s): non valid pdu_offset: %04x",
1150 /* "data may be lost", */
1151 CTCM_FUNTAIL
, dev
->name
, new_len
);
1154 skb
= __dev_alloc_skb(new_len
+4, GFP_ATOMIC
);
1157 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1158 "%s(%s): MEMORY allocation error",
1159 CTCM_FUNTAIL
, dev
->name
);
1160 priv
->stats
.rx_dropped
++;
1161 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1164 memcpy(skb_put(skb
, new_len
), pskb
->data
, new_len
);
1166 skb_reset_mac_header(skb
);
1167 skb
->dev
= pskb
->dev
;
1168 skb
->protocol
= pskb
->protocol
;
1169 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1170 *((__u32
*) skb_push(skb
, 4)) = ch
->pdu_seq
;
1173 if (do_debug_data
) {
1174 ctcm_pr_debug("%s: ToDCM_pdu_seq= %08x\n",
1175 __func__
, ch
->pdu_seq
);
1176 ctcm_pr_debug("%s: skb:%0lx "
1177 "skb len: %d \n", __func__
,
1178 (unsigned long)skb
, skb
->len
);
1179 ctcm_pr_debug("%s: up to 32 bytes "
1180 "of pdu_data sent\n", __func__
);
1181 ctcmpc_dump32((char *)skb
->data
, skb
->len
);
1185 sendrc
= netif_rx(skb
);
1186 priv
->stats
.rx_packets
++;
1187 priv
->stats
.rx_bytes
+= skblen
;
1188 skb_pull(pskb
, new_len
); /* point to next PDU */
1191 mpcginfo
= kmalloc(sizeof(struct mpcg_info
), gfp_type());
1192 if (mpcginfo
== NULL
)
1196 mpcginfo
->th
= header
;
1197 mpcginfo
->skb
= pskb
;
1198 CTCM_PR_DEBUG("%s: Not PDU - may be control pkt\n",
1201 sweep
= (struct th_sweep
*)pskb
->data
;
1202 mpcginfo
->sweep
= sweep
;
1203 if (header
->th_ch_flag
== TH_SWEEP_REQ
)
1204 mpc_rcvd_sweep_req(mpcginfo
);
1205 else if (header
->th_ch_flag
== TH_SWEEP_RESP
)
1206 mpc_rcvd_sweep_resp(mpcginfo
);
1207 else if (header
->th_blk_flag
== TH_DATA_IS_XID
) {
1208 struct xid2
*thisxid
= (struct xid2
*)pskb
->data
;
1209 skb_pull(pskb
, XID2_LENGTH
);
1210 mpcginfo
->xid
= thisxid
;
1211 fsm_event(grp
->fsm
, MPCG_EVENT_XID2
, mpcginfo
);
1212 } else if (header
->th_blk_flag
== TH_DISCONTACT
)
1213 fsm_event(grp
->fsm
, MPCG_EVENT_DISCONC
, mpcginfo
);
1214 else if (header
->th_seq_num
!= 0) {
1215 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1216 "%s(%s): control pkt expected\n",
1217 CTCM_FUNTAIL
, dev
->name
);
1218 priv
->stats
.rx_dropped
++;
1219 /* mpcginfo only used for non-data transfers */
1222 ctcmpc_dump_skb(pskb
, -8);
1227 dev_kfree_skb_any(pskb
);
1228 if (sendrc
== NET_RX_DROP
) {
1230 "The network backlog for %s is exceeded, "
1231 "package dropped\n", __func__
);
1232 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1235 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1236 __func__
, dev
->name
, ch
, ch
->id
);
1240 * tasklet helper for mpc's skb unpacking.
1242 * ch The channel to work on.
1243 * Allow flow control back pressure to occur here.
1244 * Throttling back channel can result in excessive
1245 * channel inactivity and system deact of channel
1247 void ctcmpc_bh(unsigned long thischan
)
1249 struct channel
*ch
= (struct channel
*)thischan
;
1250 struct sk_buff
*skb
;
1251 struct net_device
*dev
= ch
->netdev
;
1252 struct ctcm_priv
*priv
= dev
->ml_priv
;
1253 struct mpc_group
*grp
= priv
->mpcg
;
1255 CTCM_PR_DEBUG("%s cp:%i enter: %s() %s\n",
1256 dev
->name
, smp_processor_id(), __func__
, ch
->id
);
1257 /* caller has requested driver to throttle back */
1258 while ((fsm_getstate(grp
->fsm
) != MPCG_STATE_FLOWC
) &&
1259 (skb
= skb_dequeue(&ch
->io_queue
))) {
1260 ctcmpc_unpack_skb(ch
, skb
);
1261 if (grp
->out_of_sequence
> 20) {
1262 /* assume data loss has occurred if */
1263 /* missing seq_num for extended */
1264 /* period of time */
1265 grp
->out_of_sequence
= 0;
1266 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1269 if (skb
== skb_peek(&ch
->io_queue
))
1272 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1273 __func__
, dev
->name
, ch
, ch
->id
);
1278 * MPC Group Initializations
1280 struct mpc_group
*ctcmpc_init_mpc_group(struct ctcm_priv
*priv
)
1282 struct mpc_group
*grp
;
1284 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_INFO
,
1285 "Enter %s(%p)", CTCM_FUNTAIL
, priv
);
1287 grp
= kzalloc(sizeof(struct mpc_group
), GFP_KERNEL
);
1291 grp
->fsm
= init_fsm("mpcg", mpcg_state_names
, mpcg_event_names
,
1292 MPCG_NR_STATES
, MPCG_NR_EVENTS
, mpcg_fsm
,
1293 mpcg_fsm_len
, GFP_KERNEL
);
1294 if (grp
->fsm
== NULL
) {
1299 fsm_newstate(grp
->fsm
, MPCG_STATE_RESET
);
1300 fsm_settimer(grp
->fsm
, &grp
->timer
);
1303 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT
, GFP_ATOMIC
| GFP_DMA
);
1304 if (grp
->xid_skb
== NULL
) {
1305 kfree_fsm(grp
->fsm
);
1309 /* base xid for all channels in group */
1310 grp
->xid_skb_data
= grp
->xid_skb
->data
;
1311 grp
->xid_th
= (struct th_header
*)grp
->xid_skb
->data
;
1312 memcpy(skb_put(grp
->xid_skb
, TH_HEADER_LENGTH
),
1313 &thnorm
, TH_HEADER_LENGTH
);
1315 grp
->xid
= (struct xid2
*)skb_tail_pointer(grp
->xid_skb
);
1316 memcpy(skb_put(grp
->xid_skb
, XID2_LENGTH
), &init_xid
, XID2_LENGTH
);
1317 grp
->xid
->xid2_adj_id
= jiffies
| 0xfff00000;
1318 grp
->xid
->xid2_sender_id
= jiffies
;
1320 grp
->xid_id
= skb_tail_pointer(grp
->xid_skb
);
1321 memcpy(skb_put(grp
->xid_skb
, 4), "VTAM", 4);
1324 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT
, GFP_ATOMIC
|GFP_DMA
);
1325 if (grp
->rcvd_xid_skb
== NULL
) {
1326 kfree_fsm(grp
->fsm
);
1327 dev_kfree_skb(grp
->xid_skb
);
1331 grp
->rcvd_xid_data
= grp
->rcvd_xid_skb
->data
;
1332 grp
->rcvd_xid_th
= (struct th_header
*)grp
->rcvd_xid_skb
->data
;
1333 memcpy(skb_put(grp
->rcvd_xid_skb
, TH_HEADER_LENGTH
),
1334 &thnorm
, TH_HEADER_LENGTH
);
1335 grp
->saved_xid2
= NULL
;
1336 priv
->xid
= grp
->xid
;
1342 * The MPC Group Station FSM
1346 * MPC Group Station FSM actions
1347 * CTCM_PROTO_MPC only
1351 * NOP action for statemachines
1353 static void mpc_action_nop(fsm_instance
*fi
, int event
, void *arg
)
1358 * invoked when the device transitions to dev_stopped
1359 * MPC will stop each individual channel if a single XID failure
1360 * occurs, or will intitiate all channels be stopped if a GROUP
1361 * level failure occurs.
1363 static void mpc_action_go_inop(fsm_instance
*fi
, int event
, void *arg
)
1365 struct net_device
*dev
= arg
;
1366 struct ctcm_priv
*priv
;
1367 struct mpc_group
*grp
;
1368 struct channel
*wch
;
1370 CTCM_PR_DEBUG("Enter %s: %s\n", __func__
, dev
->name
);
1372 priv
= dev
->ml_priv
;
1374 grp
->flow_off_called
= 0;
1375 fsm_deltimer(&grp
->timer
);
1376 if (grp
->channels_terminating
)
1379 grp
->channels_terminating
= 1;
1380 grp
->saved_state
= fsm_getstate(grp
->fsm
);
1381 fsm_newstate(grp
->fsm
, MPCG_STATE_INOP
);
1382 if (grp
->saved_state
> MPCG_STATE_XID7INITF
)
1383 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
1384 "%s(%s): MPC GROUP INOPERATIVE",
1385 CTCM_FUNTAIL
, dev
->name
);
1386 if ((grp
->saved_state
!= MPCG_STATE_RESET
) ||
1387 /* dealloc_channel has been called */
1388 (grp
->port_persist
== 0))
1389 fsm_deltimer(&priv
->restart_timer
);
1391 wch
= priv
->channel
[CTCM_WRITE
];
1393 switch (grp
->saved_state
) {
1394 case MPCG_STATE_RESET
:
1395 case MPCG_STATE_INOP
:
1396 case MPCG_STATE_XID2INITW
:
1397 case MPCG_STATE_XID0IOWAIT
:
1398 case MPCG_STATE_XID2INITX
:
1399 case MPCG_STATE_XID7INITW
:
1400 case MPCG_STATE_XID7INITX
:
1401 case MPCG_STATE_XID0IOWAIX
:
1402 case MPCG_STATE_XID7INITI
:
1403 case MPCG_STATE_XID7INITZ
:
1404 case MPCG_STATE_XID7INITF
:
1406 case MPCG_STATE_FLOWC
:
1407 case MPCG_STATE_READY
:
1409 tasklet_hi_schedule(&wch
->ch_disc_tasklet
);
1412 grp
->xid2_tgnum
= 0;
1413 grp
->group_max_buflen
= 0; /*min of all received */
1414 grp
->outstanding_xid2
= 0;
1415 grp
->outstanding_xid7
= 0;
1416 grp
->outstanding_xid7_p2
= 0;
1417 grp
->saved_xid2
= NULL
;
1419 grp
->changed_side
= 0;
1421 grp
->rcvd_xid_skb
->data
= grp
->rcvd_xid_data
;
1422 skb_reset_tail_pointer(grp
->rcvd_xid_skb
);
1423 grp
->rcvd_xid_skb
->len
= 0;
1424 grp
->rcvd_xid_th
= (struct th_header
*)grp
->rcvd_xid_skb
->data
;
1425 memcpy(skb_put(grp
->rcvd_xid_skb
, TH_HEADER_LENGTH
), &thnorm
,
1428 if (grp
->send_qllc_disc
== 1) {
1429 grp
->send_qllc_disc
= 0;
1430 mpc_send_qllc_discontact(dev
);
1433 /* DO NOT issue DEV_EVENT_STOP directly out of this code */
1434 /* This can result in INOP of VTAM PU due to halting of */
1435 /* outstanding IO which causes a sense to be returned */
1436 /* Only about 3 senses are allowed and then IOS/VTAM will*/
1437 /* become unreachable without manual intervention */
1438 if ((grp
->port_persist
== 1) || (grp
->alloc_called
)) {
1439 grp
->alloc_called
= 0;
1440 fsm_deltimer(&priv
->restart_timer
);
1441 fsm_addtimer(&priv
->restart_timer
, 500, DEV_EVENT_RESTART
, dev
);
1442 fsm_newstate(grp
->fsm
, MPCG_STATE_RESET
);
1443 if (grp
->saved_state
> MPCG_STATE_XID7INITF
)
1444 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_ALWAYS
,
1445 "%s(%s): MPC GROUP RECOVERY SCHEDULED",
1446 CTCM_FUNTAIL
, dev
->name
);
1448 fsm_deltimer(&priv
->restart_timer
);
1449 fsm_addtimer(&priv
->restart_timer
, 500, DEV_EVENT_STOP
, dev
);
1450 fsm_newstate(grp
->fsm
, MPCG_STATE_RESET
);
1451 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_ALWAYS
,
1452 "%s(%s): NO MPC GROUP RECOVERY ATTEMPTED",
1453 CTCM_FUNTAIL
, dev
->name
);
1458 * Handle mpc group action timeout.
1459 * MPC Group Station FSM action
1460 * CTCM_PROTO_MPC only
1462 * fi An instance of an mpc_group fsm.
1463 * event The event, just happened.
1464 * arg Generic pointer, casted from net_device * upon call.
1466 static void mpc_action_timeout(fsm_instance
*fi
, int event
, void *arg
)
1468 struct net_device
*dev
= arg
;
1469 struct ctcm_priv
*priv
;
1470 struct mpc_group
*grp
;
1471 struct channel
*wch
;
1472 struct channel
*rch
;
1474 priv
= dev
->ml_priv
;
1476 wch
= priv
->channel
[CTCM_WRITE
];
1477 rch
= priv
->channel
[CTCM_READ
];
1479 switch (fsm_getstate(grp
->fsm
)) {
1480 case MPCG_STATE_XID2INITW
:
1481 /* Unless there is outstanding IO on the */
1482 /* channel just return and wait for ATTN */
1483 /* interrupt to begin XID negotiations */
1484 if ((fsm_getstate(rch
->fsm
) == CH_XID0_PENDING
) &&
1485 (fsm_getstate(wch
->fsm
) == CH_XID0_PENDING
))
1488 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1491 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_DEBUG
,
1493 CTCM_FUNTAIL
, dev
->name
);
1498 * MPC Group Station FSM action
1499 * CTCM_PROTO_MPC only
1501 void mpc_action_discontact(fsm_instance
*fi
, int event
, void *arg
)
1503 struct mpcg_info
*mpcginfo
= arg
;
1504 struct channel
*ch
= mpcginfo
->ch
;
1505 struct net_device
*dev
;
1506 struct ctcm_priv
*priv
;
1507 struct mpc_group
*grp
;
1512 priv
= dev
->ml_priv
;
1514 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
1516 CTCM_FUNTAIL
, dev
->name
, ch
->id
);
1518 grp
->send_qllc_disc
= 1;
1519 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1528 * MPC Group Station - not part of FSM
1529 * CTCM_PROTO_MPC only
1530 * called from add_channel in ctcm_main.c
1532 void mpc_action_send_discontact(unsigned long thischan
)
1535 struct channel
*ch
= (struct channel
*)thischan
;
1536 unsigned long saveflags
= 0;
1538 spin_lock_irqsave(get_ccwdev_lock(ch
->cdev
), saveflags
);
1539 rc
= ccw_device_start(ch
->cdev
, &ch
->ccw
[15],
1540 (unsigned long)ch
, 0xff, 0);
1541 spin_unlock_irqrestore(get_ccwdev_lock(ch
->cdev
), saveflags
);
1544 ctcm_ccw_check_rc(ch
, rc
, (char *)__func__
);
1552 * helper function of mpc FSM
1553 * CTCM_PROTO_MPC only
1554 * mpc_action_rcvd_xid7
1556 static int mpc_validate_xid(struct mpcg_info
*mpcginfo
)
1558 struct channel
*ch
= mpcginfo
->ch
;
1559 struct net_device
*dev
= ch
->netdev
;
1560 struct ctcm_priv
*priv
= dev
->ml_priv
;
1561 struct mpc_group
*grp
= priv
->mpcg
;
1562 struct xid2
*xid
= mpcginfo
->xid
;
1566 int len
= TH_HEADER_LENGTH
+ PDU_HEADER_LENGTH
;
1568 CTCM_PR_DEBUG("Enter %s: xid=%p\n", __func__
, xid
);
1572 /* XID REJECTED: xid == NULL */
1573 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1574 "%s(%s): xid = NULL",
1575 CTCM_FUNTAIL
, ch
->id
);
1579 CTCM_D3_DUMP((char *)xid
, XID2_LENGTH
);
1581 /*the received direction should be the opposite of ours */
1582 if (((CHANNEL_DIRECTION(ch
->flags
) == CTCM_READ
) ? XID2_WRITE_SIDE
:
1583 XID2_READ_SIDE
) != xid
->xid2_dlc_type
) {
1585 /* XID REJECTED: r/w channel pairing mismatch */
1586 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1587 "%s(%s): r/w channel pairing mismatch",
1588 CTCM_FUNTAIL
, ch
->id
);
1592 if (xid
->xid2_dlc_type
== XID2_READ_SIDE
) {
1593 CTCM_PR_DEBUG("%s: grpmaxbuf:%d xid2buflen:%d\n", __func__
,
1594 grp
->group_max_buflen
, xid
->xid2_buf_len
);
1596 if (grp
->group_max_buflen
== 0 || grp
->group_max_buflen
>
1597 xid
->xid2_buf_len
- len
)
1598 grp
->group_max_buflen
= xid
->xid2_buf_len
- len
;
1601 if (grp
->saved_xid2
== NULL
) {
1603 (struct xid2
*)skb_tail_pointer(grp
->rcvd_xid_skb
);
1605 memcpy(skb_put(grp
->rcvd_xid_skb
,
1606 XID2_LENGTH
), xid
, XID2_LENGTH
);
1607 grp
->rcvd_xid_skb
->data
= grp
->rcvd_xid_data
;
1609 skb_reset_tail_pointer(grp
->rcvd_xid_skb
);
1610 grp
->rcvd_xid_skb
->len
= 0;
1612 /* convert two 32 bit numbers into 1 64 bit for id compare */
1613 our_id
= (__u64
)priv
->xid
->xid2_adj_id
;
1614 our_id
= our_id
<< 32;
1615 our_id
= our_id
+ priv
->xid
->xid2_sender_id
;
1616 their_id
= (__u64
)xid
->xid2_adj_id
;
1617 their_id
= their_id
<< 32;
1618 their_id
= their_id
+ xid
->xid2_sender_id
;
1619 /* lower id assume the xside role */
1620 if (our_id
< their_id
) {
1622 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
1623 "%s(%s): WE HAVE LOW ID - TAKE XSIDE",
1624 CTCM_FUNTAIL
, ch
->id
);
1627 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
1628 "%s(%s): WE HAVE HIGH ID - TAKE YSIDE",
1629 CTCM_FUNTAIL
, ch
->id
);
1633 if (xid
->xid2_flag4
!= grp
->saved_xid2
->xid2_flag4
) {
1635 /* XID REJECTED: xid flag byte4 mismatch */
1636 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1637 "%s(%s): xid flag byte4 mismatch",
1638 CTCM_FUNTAIL
, ch
->id
);
1640 if (xid
->xid2_flag2
== 0x40) {
1642 /* XID REJECTED - xid NOGOOD */
1643 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1644 "%s(%s): xid NOGOOD",
1645 CTCM_FUNTAIL
, ch
->id
);
1647 if (xid
->xid2_adj_id
!= grp
->saved_xid2
->xid2_adj_id
) {
1649 /* XID REJECTED - Adjacent Station ID Mismatch */
1650 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1651 "%s(%s): Adjacent Station ID Mismatch",
1652 CTCM_FUNTAIL
, ch
->id
);
1654 if (xid
->xid2_sender_id
!= grp
->saved_xid2
->xid2_sender_id
) {
1656 /* XID REJECTED - Sender Address Mismatch */
1657 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1658 "%s(%s): Sender Address Mismatch",
1659 CTCM_FUNTAIL
, ch
->id
);
1665 "The XID used in the MPC protocol is not valid, "
1667 priv
->xid
->xid2_flag2
= 0x40;
1668 grp
->saved_xid2
->xid2_flag2
= 0x40;
1675 * MPC Group Station FSM action
1676 * CTCM_PROTO_MPC only
1678 static void mpc_action_side_xid(fsm_instance
*fsm
, void *arg
, int side
)
1680 struct channel
*ch
= arg
;
1683 unsigned long saveflags
= 0; /* avoids compiler warning with
1684 spin_unlock_irqrestore */
1686 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1687 __func__
, smp_processor_id(), ch
, ch
->id
);
1689 if (ctcm_checkalloc_buffer(ch
))
1693 * skb data-buffer referencing:
1695 ch
->trans_skb
->data
= ch
->trans_skb_data
;
1696 skb_reset_tail_pointer(ch
->trans_skb
);
1697 ch
->trans_skb
->len
= 0;
1698 /* result of the previous 3 statements is NOT always
1699 * already set after ctcm_checkalloc_buffer
1700 * because of possible reuse of the trans_skb
1702 memset(ch
->trans_skb
->data
, 0, 16);
1703 ch
->rcvd_xid_th
= (struct th_header
*)ch
->trans_skb_data
;
1704 /* check is main purpose here: */
1705 skb_put(ch
->trans_skb
, TH_HEADER_LENGTH
);
1706 ch
->rcvd_xid
= (struct xid2
*)skb_tail_pointer(ch
->trans_skb
);
1707 /* check is main purpose here: */
1708 skb_put(ch
->trans_skb
, XID2_LENGTH
);
1709 ch
->rcvd_xid_id
= skb_tail_pointer(ch
->trans_skb
);
1710 /* cleanup back to startpoint */
1711 ch
->trans_skb
->data
= ch
->trans_skb_data
;
1712 skb_reset_tail_pointer(ch
->trans_skb
);
1713 ch
->trans_skb
->len
= 0;
1715 /* non-checking rewrite of above skb data-buffer referencing: */
1717 memset(ch->trans_skb->data, 0, 16);
1718 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1719 ch->rcvd_xid = (struct xid2 *)(ch->trans_skb_data + TH_HEADER_LENGTH);
1720 ch->rcvd_xid_id = ch->trans_skb_data + TH_HEADER_LENGTH + XID2_LENGTH;
1723 ch
->ccw
[8].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1724 ch
->ccw
[8].count
= 0;
1725 ch
->ccw
[8].cda
= 0x00;
1727 if (!(ch
->xid_th
&& ch
->xid
&& ch
->xid_id
))
1728 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_INFO
,
1729 "%s(%s): xid_th=%p, xid=%p, xid_id=%p",
1730 CTCM_FUNTAIL
, ch
->id
, ch
->xid_th
, ch
->xid
, ch
->xid_id
);
1732 if (side
== XSIDE
) {
1733 /* mpc_action_xside_xid */
1734 if (ch
->xid_th
== NULL
)
1736 ch
->ccw
[9].cmd_code
= CCW_CMD_WRITE
;
1737 ch
->ccw
[9].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1738 ch
->ccw
[9].count
= TH_HEADER_LENGTH
;
1739 ch
->ccw
[9].cda
= virt_to_phys(ch
->xid_th
);
1741 if (ch
->xid
== NULL
)
1743 ch
->ccw
[10].cmd_code
= CCW_CMD_WRITE
;
1744 ch
->ccw
[10].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1745 ch
->ccw
[10].count
= XID2_LENGTH
;
1746 ch
->ccw
[10].cda
= virt_to_phys(ch
->xid
);
1748 ch
->ccw
[11].cmd_code
= CCW_CMD_READ
;
1749 ch
->ccw
[11].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1750 ch
->ccw
[11].count
= TH_HEADER_LENGTH
;
1751 ch
->ccw
[11].cda
= virt_to_phys(ch
->rcvd_xid_th
);
1753 ch
->ccw
[12].cmd_code
= CCW_CMD_READ
;
1754 ch
->ccw
[12].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1755 ch
->ccw
[12].count
= XID2_LENGTH
;
1756 ch
->ccw
[12].cda
= virt_to_phys(ch
->rcvd_xid
);
1758 ch
->ccw
[13].cmd_code
= CCW_CMD_READ
;
1759 ch
->ccw
[13].cda
= virt_to_phys(ch
->rcvd_xid_id
);
1761 } else { /* side == YSIDE : mpc_action_yside_xid */
1762 ch
->ccw
[9].cmd_code
= CCW_CMD_READ
;
1763 ch
->ccw
[9].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1764 ch
->ccw
[9].count
= TH_HEADER_LENGTH
;
1765 ch
->ccw
[9].cda
= virt_to_phys(ch
->rcvd_xid_th
);
1767 ch
->ccw
[10].cmd_code
= CCW_CMD_READ
;
1768 ch
->ccw
[10].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1769 ch
->ccw
[10].count
= XID2_LENGTH
;
1770 ch
->ccw
[10].cda
= virt_to_phys(ch
->rcvd_xid
);
1772 if (ch
->xid_th
== NULL
)
1774 ch
->ccw
[11].cmd_code
= CCW_CMD_WRITE
;
1775 ch
->ccw
[11].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1776 ch
->ccw
[11].count
= TH_HEADER_LENGTH
;
1777 ch
->ccw
[11].cda
= virt_to_phys(ch
->xid_th
);
1779 if (ch
->xid
== NULL
)
1781 ch
->ccw
[12].cmd_code
= CCW_CMD_WRITE
;
1782 ch
->ccw
[12].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1783 ch
->ccw
[12].count
= XID2_LENGTH
;
1784 ch
->ccw
[12].cda
= virt_to_phys(ch
->xid
);
1786 if (ch
->xid_id
== NULL
)
1788 ch
->ccw
[13].cmd_code
= CCW_CMD_WRITE
;
1789 ch
->ccw
[13].cda
= virt_to_phys(ch
->xid_id
);
1792 ch
->ccw
[13].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1793 ch
->ccw
[13].count
= 4;
1795 ch
->ccw
[14].cmd_code
= CCW_CMD_NOOP
;
1796 ch
->ccw
[14].flags
= CCW_FLAG_SLI
;
1797 ch
->ccw
[14].count
= 0;
1798 ch
->ccw
[14].cda
= 0;
1800 CTCM_CCW_DUMP((char *)&ch
->ccw
[8], sizeof(struct ccw1
) * 7);
1801 CTCM_D3_DUMP((char *)ch
->xid_th
, TH_HEADER_LENGTH
);
1802 CTCM_D3_DUMP((char *)ch
->xid
, XID2_LENGTH
);
1803 CTCM_D3_DUMP((char *)ch
->xid_id
, 4);
1806 /* Such conditional locking is a known problem for
1807 * sparse because its static undeterministic.
1808 * Warnings should be ignored here. */
1809 spin_lock_irqsave(get_ccwdev_lock(ch
->cdev
), saveflags
);
1813 fsm_addtimer(&ch
->timer
, 5000 , CTC_EVENT_TIMER
, ch
);
1814 rc
= ccw_device_start(ch
->cdev
, &ch
->ccw
[8],
1815 (unsigned long)ch
, 0xff, 0);
1817 if (gotlock
) /* see remark above about conditional locking */
1818 spin_unlock_irqrestore(get_ccwdev_lock(ch
->cdev
), saveflags
);
1821 ctcm_ccw_check_rc(ch
, rc
,
1822 (side
== XSIDE
) ? "x-side XID" : "y-side XID");
1826 CTCM_PR_DEBUG("Exit %s: ch=0x%p id=%s\n",
1827 __func__
, ch
, ch
->id
);
1833 * MPC Group Station FSM action
1834 * CTCM_PROTO_MPC only
1836 static void mpc_action_xside_xid(fsm_instance
*fsm
, int event
, void *arg
)
1838 mpc_action_side_xid(fsm
, arg
, XSIDE
);
1842 * MPC Group Station FSM action
1843 * CTCM_PROTO_MPC only
1845 static void mpc_action_yside_xid(fsm_instance
*fsm
, int event
, void *arg
)
1847 mpc_action_side_xid(fsm
, arg
, YSIDE
);
1851 * MPC Group Station FSM action
1852 * CTCM_PROTO_MPC only
1854 static void mpc_action_doxid0(fsm_instance
*fsm
, int event
, void *arg
)
1856 struct channel
*ch
= arg
;
1857 struct net_device
*dev
= ch
->netdev
;
1858 struct ctcm_priv
*priv
= dev
->ml_priv
;
1859 struct mpc_group
*grp
= priv
->mpcg
;
1861 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1862 __func__
, smp_processor_id(), ch
, ch
->id
);
1864 if (ch
->xid
== NULL
) {
1865 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1866 "%s(%s): ch->xid == NULL",
1867 CTCM_FUNTAIL
, dev
->name
);
1871 fsm_newstate(ch
->fsm
, CH_XID0_INPROGRESS
);
1873 ch
->xid
->xid2_option
= XID2_0
;
1875 switch (fsm_getstate(grp
->fsm
)) {
1876 case MPCG_STATE_XID2INITW
:
1877 case MPCG_STATE_XID2INITX
:
1878 ch
->ccw
[8].cmd_code
= CCW_CMD_SENSE_CMD
;
1880 case MPCG_STATE_XID0IOWAIT
:
1881 case MPCG_STATE_XID0IOWAIX
:
1882 ch
->ccw
[8].cmd_code
= CCW_CMD_WRITE_CTL
;
1886 fsm_event(grp
->fsm
, MPCG_EVENT_DOIO
, ch
);
1892 * MPC Group Station FSM action
1893 * CTCM_PROTO_MPC only
1895 static void mpc_action_doxid7(fsm_instance
*fsm
, int event
, void *arg
)
1897 struct net_device
*dev
= arg
;
1898 struct ctcm_priv
*priv
= dev
->ml_priv
;
1899 struct mpc_group
*grp
= NULL
;
1908 for (direction
= CTCM_READ
; direction
<= CTCM_WRITE
; direction
++) {
1909 struct channel
*ch
= priv
->channel
[direction
];
1910 struct xid2
*thisxid
= ch
->xid
;
1911 ch
->xid_skb
->data
= ch
->xid_skb_data
;
1912 skb_reset_tail_pointer(ch
->xid_skb
);
1913 ch
->xid_skb
->len
= 0;
1914 thisxid
->xid2_option
= XID2_7
;
1918 if (grp
->outstanding_xid7_p2
> 0) {
1919 if (grp
->roll
== YSIDE
) {
1920 if (fsm_getstate(ch
->fsm
) == CH_XID7_PENDING1
) {
1921 fsm_newstate(ch
->fsm
, CH_XID7_PENDING2
);
1922 ch
->ccw
[8].cmd_code
= CCW_CMD_SENSE_CMD
;
1923 memcpy(skb_put(ch
->xid_skb
,
1925 &thdummy
, TH_HEADER_LENGTH
);
1928 } else if (fsm_getstate(ch
->fsm
) < CH_XID7_PENDING2
) {
1929 fsm_newstate(ch
->fsm
, CH_XID7_PENDING2
);
1930 ch
->ccw
[8].cmd_code
= CCW_CMD_WRITE_CTL
;
1931 memcpy(skb_put(ch
->xid_skb
,
1933 &thnorm
, TH_HEADER_LENGTH
);
1938 if (grp
->roll
== YSIDE
) {
1939 if (fsm_getstate(ch
->fsm
) < CH_XID7_PENDING4
) {
1940 fsm_newstate(ch
->fsm
, CH_XID7_PENDING4
);
1941 memcpy(skb_put(ch
->xid_skb
,
1943 &thnorm
, TH_HEADER_LENGTH
);
1944 ch
->ccw
[8].cmd_code
= CCW_CMD_WRITE_CTL
;
1947 } else if (fsm_getstate(ch
->fsm
) == CH_XID7_PENDING3
) {
1948 fsm_newstate(ch
->fsm
, CH_XID7_PENDING4
);
1949 ch
->ccw
[8].cmd_code
= CCW_CMD_SENSE_CMD
;
1950 memcpy(skb_put(ch
->xid_skb
, TH_HEADER_LENGTH
),
1951 &thdummy
, TH_HEADER_LENGTH
);
1957 fsm_event(grp
->fsm
, MPCG_EVENT_DOIO
, ch
);
1964 * MPC Group Station FSM action
1965 * CTCM_PROTO_MPC only
1967 static void mpc_action_rcvd_xid0(fsm_instance
*fsm
, int event
, void *arg
)
1970 struct mpcg_info
*mpcginfo
= arg
;
1971 struct channel
*ch
= mpcginfo
->ch
;
1972 struct net_device
*dev
= ch
->netdev
;
1973 struct ctcm_priv
*priv
= dev
->ml_priv
;
1974 struct mpc_group
*grp
= priv
->mpcg
;
1976 CTCM_PR_DEBUG("%s: ch-id:%s xid2:%i xid7:%i xidt_p2:%i \n",
1977 __func__
, ch
->id
, grp
->outstanding_xid2
,
1978 grp
->outstanding_xid7
, grp
->outstanding_xid7_p2
);
1980 if (fsm_getstate(ch
->fsm
) < CH_XID7_PENDING
)
1981 fsm_newstate(ch
->fsm
, CH_XID7_PENDING
);
1983 grp
->outstanding_xid2
--;
1984 grp
->outstanding_xid7
++;
1985 grp
->outstanding_xid7_p2
++;
1987 /* must change state before validating xid to */
1988 /* properly handle interim interrupts received*/
1989 switch (fsm_getstate(grp
->fsm
)) {
1990 case MPCG_STATE_XID2INITW
:
1991 fsm_newstate(grp
->fsm
, MPCG_STATE_XID2INITX
);
1992 mpc_validate_xid(mpcginfo
);
1994 case MPCG_STATE_XID0IOWAIT
:
1995 fsm_newstate(grp
->fsm
, MPCG_STATE_XID0IOWAIX
);
1996 mpc_validate_xid(mpcginfo
);
1998 case MPCG_STATE_XID2INITX
:
1999 if (grp
->outstanding_xid2
== 0) {
2000 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITW
);
2001 mpc_validate_xid(mpcginfo
);
2002 fsm_event(grp
->fsm
, MPCG_EVENT_XID2DONE
, dev
);
2005 case MPCG_STATE_XID0IOWAIX
:
2006 if (grp
->outstanding_xid2
== 0) {
2007 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITI
);
2008 mpc_validate_xid(mpcginfo
);
2009 fsm_event(grp
->fsm
, MPCG_EVENT_XID2DONE
, dev
);
2015 CTCM_PR_DEBUG("ctcmpc:%s() %s xid2:%i xid7:%i xidt_p2:%i \n",
2016 __func__
, ch
->id
, grp
->outstanding_xid2
,
2017 grp
->outstanding_xid7
, grp
->outstanding_xid7_p2
);
2018 CTCM_PR_DEBUG("ctcmpc:%s() %s grpstate: %s chanstate: %s \n",
2020 fsm_getstate_str(grp
->fsm
), fsm_getstate_str(ch
->fsm
));
2027 * MPC Group Station FSM action
2028 * CTCM_PROTO_MPC only
2030 static void mpc_action_rcvd_xid7(fsm_instance
*fsm
, int event
, void *arg
)
2032 struct mpcg_info
*mpcginfo
= arg
;
2033 struct channel
*ch
= mpcginfo
->ch
;
2034 struct net_device
*dev
= ch
->netdev
;
2035 struct ctcm_priv
*priv
= dev
->ml_priv
;
2036 struct mpc_group
*grp
= priv
->mpcg
;
2038 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
2039 __func__
, smp_processor_id(), ch
, ch
->id
);
2040 CTCM_PR_DEBUG("%s: outstanding_xid7: %i, outstanding_xid7_p2: %i\n",
2041 __func__
, grp
->outstanding_xid7
, grp
->outstanding_xid7_p2
);
2043 grp
->outstanding_xid7
--;
2044 ch
->xid_skb
->data
= ch
->xid_skb_data
;
2045 skb_reset_tail_pointer(ch
->xid_skb
);
2046 ch
->xid_skb
->len
= 0;
2048 switch (fsm_getstate(grp
->fsm
)) {
2049 case MPCG_STATE_XID7INITI
:
2050 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITZ
);
2051 mpc_validate_xid(mpcginfo
);
2053 case MPCG_STATE_XID7INITW
:
2054 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITX
);
2055 mpc_validate_xid(mpcginfo
);
2057 case MPCG_STATE_XID7INITZ
:
2058 case MPCG_STATE_XID7INITX
:
2059 if (grp
->outstanding_xid7
== 0) {
2060 if (grp
->outstanding_xid7_p2
> 0) {
2061 grp
->outstanding_xid7
=
2062 grp
->outstanding_xid7_p2
;
2063 grp
->outstanding_xid7_p2
= 0;
2065 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITF
);
2067 mpc_validate_xid(mpcginfo
);
2068 fsm_event(grp
->fsm
, MPCG_EVENT_XID7DONE
, dev
);
2071 mpc_validate_xid(mpcginfo
);
2079 * mpc_action helper of an MPC Group Station FSM action
2080 * CTCM_PROTO_MPC only
2082 static int mpc_send_qllc_discontact(struct net_device
*dev
)
2085 struct sk_buff
*skb
;
2086 struct qllc
*qllcptr
;
2087 struct ctcm_priv
*priv
= dev
->ml_priv
;
2088 struct mpc_group
*grp
= priv
->mpcg
;
2090 CTCM_PR_DEBUG("%s: GROUP STATE: %s\n",
2091 __func__
, mpcg_state_names
[grp
->saved_state
]);
2093 switch (grp
->saved_state
) {
2095 * establish conn callback function is
2096 * preferred method to report failure
2098 case MPCG_STATE_XID0IOWAIT
:
2099 case MPCG_STATE_XID0IOWAIX
:
2100 case MPCG_STATE_XID7INITI
:
2101 case MPCG_STATE_XID7INITZ
:
2102 case MPCG_STATE_XID2INITW
:
2103 case MPCG_STATE_XID2INITX
:
2104 case MPCG_STATE_XID7INITW
:
2105 case MPCG_STATE_XID7INITX
:
2106 if (grp
->estconnfunc
) {
2107 grp
->estconnfunc(grp
->port_num
, -1, 0);
2108 grp
->estconnfunc
= NULL
;
2111 case MPCG_STATE_FLOWC
:
2112 case MPCG_STATE_READY
:
2113 grp
->send_qllc_disc
= 2;
2114 new_len
= sizeof(struct qllc
);
2115 qllcptr
= kzalloc(new_len
, gfp_type() | GFP_DMA
);
2116 if (qllcptr
== NULL
) {
2117 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
2118 "%s(%s): qllcptr allocation error",
2119 CTCM_FUNTAIL
, dev
->name
);
2123 qllcptr
->qllc_address
= 0xcc;
2124 qllcptr
->qllc_commands
= 0x03;
2126 skb
= __dev_alloc_skb(new_len
, GFP_ATOMIC
);
2129 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
2130 "%s(%s): skb allocation error",
2131 CTCM_FUNTAIL
, dev
->name
);
2132 priv
->stats
.rx_dropped
++;
2137 memcpy(skb_put(skb
, new_len
), qllcptr
, new_len
);
2140 if (skb_headroom(skb
) < 4) {
2141 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
2142 "%s(%s): skb_headroom error",
2143 CTCM_FUNTAIL
, dev
->name
);
2144 dev_kfree_skb_any(skb
);
2148 *((__u32
*)skb_push(skb
, 4)) =
2149 priv
->channel
[CTCM_READ
]->pdu_seq
;
2150 priv
->channel
[CTCM_READ
]->pdu_seq
++;
2151 CTCM_PR_DBGDATA("ctcmpc: %s ToDCM_pdu_seq= %08x\n",
2152 __func__
, priv
->channel
[CTCM_READ
]->pdu_seq
);
2154 /* receipt of CC03 resets anticipated sequence number on
2156 priv
->channel
[CTCM_READ
]->pdu_seq
= 0x00;
2157 skb_reset_mac_header(skb
);
2159 skb
->protocol
= htons(ETH_P_SNAP
);
2160 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2162 CTCM_D3_DUMP(skb
->data
, (sizeof(struct qllc
) + 4));
2173 /* --- This is the END my friend --- */