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>
47 #include <linux/bitops.h>
48 #include <linux/uaccess.h>
49 #include <linux/wait.h>
50 #include <linux/moduleparam.h>
51 #include <asm/ccwdev.h>
52 #include <asm/ccwgroup.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 scnprintf(addr
, sizeof(addr
), "%16.16llx", (__u64
)rptr
);
149 scnprintf(boff
, sizeof(boff
), "%4.4X", (__u32
)ct
);
153 if ((sw
== 4) || (sw
== 12))
158 scnprintf(tbuf
, sizeof(tbuf
), "%2.2llX", (__u64
)*ptr
);
162 if ((0 != isprint(*ptr
)) && (*ptr
>= 0x20))
172 if ((strcmp(duphex
, bhex
)) != 0) {
174 scnprintf(tdup
, sizeof(tdup
),
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 scnprintf(tdup
, sizeof(tdup
),
201 "Duplicate as above to %s", addr
);
202 ctcm_pr_debug(" --- %s ---\n", tdup
);
204 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
205 addr
, boff
, bhex
, basc
);
208 scnprintf(tdup
, sizeof(tdup
),
209 "Duplicate as above to %s", addr
);
210 ctcm_pr_debug(" --- %s ---\n", tdup
);
213 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
214 addr
, boff
, bhex
, basc
);
220 } /* end of ctcmpc_dumpit */
225 * Dump header and first 16 bytes of an sk_buff for debugging purposes.
227 * skb The sk_buff to dump.
228 * offset Offset relative to skb-data, where to start the dump.
230 void ctcmpc_dump_skb(struct sk_buff
*skb
, int offset
)
233 struct th_header
*header
;
242 header
= (struct th_header
*)p
;
244 ctcm_pr_debug("dump:\n");
245 ctcm_pr_debug("skb len=%d \n", skb
->len
);
247 switch (header
->th_ch_flag
) {
252 if ((header
->th_blk_flag
== TH_DATA_IS_XID
) &&
253 (header
->th_is_xid
== 0x01))
263 pheader
= (struct pdu
*)p
;
264 ctcm_pr_debug("pdu->offset: %d hex: %04x\n",
265 pheader
->pdu_offset
, pheader
->pdu_offset
);
266 ctcm_pr_debug("pdu->flag : %02x\n", pheader
->pdu_flag
);
267 ctcm_pr_debug("pdu->proto : %02x\n", pheader
->pdu_proto
);
268 ctcm_pr_debug("pdu->seq : %02x\n", pheader
->pdu_seq
);
272 ctcm_pr_debug("th->seg : %02x\n", header
->th_seg
);
273 ctcm_pr_debug("th->ch : %02x\n", header
->th_ch_flag
);
274 ctcm_pr_debug("th->blk_flag: %02x\n", header
->th_blk_flag
);
275 ctcm_pr_debug("th->type : %s\n",
276 (header
->th_is_xid
) ? "DATA" : "XID");
277 ctcm_pr_debug("th->seqnum : %04x\n", header
->th_seq_num
);
283 ctcm_pr_debug("data: ");
284 for (i
= 0; i
< bl
; i
++)
285 ctcm_pr_debug("%02x%s", *p
++, (i
% 16) ? " " : "\n");
290 static struct net_device
*ctcmpc_get_dev(int port_num
)
293 struct net_device
*dev
;
294 struct ctcm_priv
*priv
;
296 scnprintf(device
, sizeof(device
), "%s%i", MPC_DEVICE_NAME
, port_num
);
298 dev
= __dev_get_by_name(&init_net
, device
);
301 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
302 "%s: Device not found by name: %s",
303 CTCM_FUNTAIL
, device
);
308 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
309 "%s(%s): dev->ml_priv is NULL",
310 CTCM_FUNTAIL
, device
);
313 if (priv
->mpcg
== NULL
) {
314 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
315 "%s(%s): priv->mpcg is NULL",
316 CTCM_FUNTAIL
, device
);
323 * ctc_mpc_alloc_channel
324 * (exported interface)
326 * Device Initialization :
327 * ACTPATH driven IO operations
329 int ctc_mpc_alloc_channel(int port_num
, void (*callback
)(int, int))
331 struct net_device
*dev
;
332 struct mpc_group
*grp
;
333 struct ctcm_priv
*priv
;
335 dev
= ctcmpc_get_dev(port_num
);
341 grp
->allochanfunc
= callback
;
342 grp
->port_num
= port_num
;
343 grp
->port_persist
= 1;
345 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_INFO
,
347 CTCM_FUNTAIL
, dev
->name
, fsm_getstate_str(grp
->fsm
));
349 switch (fsm_getstate(grp
->fsm
)) {
350 case MPCG_STATE_INOP
:
351 /* Group is in the process of terminating */
352 grp
->alloc_called
= 1;
354 case MPCG_STATE_RESET
:
355 /* MPC Group will transition to state */
356 /* MPCG_STATE_XID2INITW iff the minimum number */
357 /* of 1 read and 1 write channel have successfully*/
359 /*fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);*/
361 grp
->send_qllc_disc
= 1;
363 case MPCG_STATE_XID0IOWAIT
:
364 fsm_deltimer(&grp
->timer
);
365 grp
->outstanding_xid2
= 0;
366 grp
->outstanding_xid7
= 0;
367 grp
->outstanding_xid7_p2
= 0;
368 grp
->saved_xid2
= NULL
;
371 fsm_event(priv
->fsm
, DEV_EVENT_START
, dev
);
373 case MPCG_STATE_READY
:
374 /* XID exchanges completed after PORT was activated */
375 /* Link station already active */
376 /* Maybe timing issue...retry callback */
377 grp
->allocchan_callback_retries
++;
378 if (grp
->allocchan_callback_retries
< 4) {
379 if (grp
->allochanfunc
)
380 grp
->allochanfunc(grp
->port_num
,
381 grp
->group_max_buflen
);
383 /* there are problems...bail out */
384 /* there may be a state mismatch so restart */
385 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
386 grp
->allocchan_callback_retries
= 0;
393 EXPORT_SYMBOL(ctc_mpc_alloc_channel
);
396 * ctc_mpc_establish_connectivity
397 * (exported interface)
399 void ctc_mpc_establish_connectivity(int port_num
,
400 void (*callback
)(int, int, int))
402 struct net_device
*dev
;
403 struct mpc_group
*grp
;
404 struct ctcm_priv
*priv
;
405 struct channel
*rch
, *wch
;
407 dev
= ctcmpc_get_dev(port_num
);
412 rch
= priv
->channel
[CTCM_READ
];
413 wch
= priv
->channel
[CTCM_WRITE
];
415 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_INFO
,
417 CTCM_FUNTAIL
, dev
->name
, fsm_getstate_str(grp
->fsm
));
419 grp
->estconnfunc
= callback
;
420 grp
->port_num
= port_num
;
422 switch (fsm_getstate(grp
->fsm
)) {
423 case MPCG_STATE_READY
:
424 /* XID exchanges completed after PORT was activated */
425 /* Link station already active */
426 /* Maybe timing issue...retry callback */
427 fsm_deltimer(&grp
->timer
);
428 grp
->estconn_callback_retries
++;
429 if (grp
->estconn_callback_retries
< 4) {
430 if (grp
->estconnfunc
) {
431 grp
->estconnfunc(grp
->port_num
, 0,
432 grp
->group_max_buflen
);
433 grp
->estconnfunc
= NULL
;
436 /* there are problems...bail out */
437 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
438 grp
->estconn_callback_retries
= 0;
441 case MPCG_STATE_INOP
:
442 case MPCG_STATE_RESET
:
443 /* MPC Group is not ready to start XID - min num of */
444 /* 1 read and 1 write channel have not been acquired*/
446 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
447 "%s(%s): REJECTED - inactive channels",
448 CTCM_FUNTAIL
, dev
->name
);
449 if (grp
->estconnfunc
) {
450 grp
->estconnfunc(grp
->port_num
, -1, 0);
451 grp
->estconnfunc
= NULL
;
454 case MPCG_STATE_XID2INITW
:
455 /* alloc channel was called but no XID exchange */
456 /* has occurred. initiate xside XID exchange */
457 /* make sure yside XID0 processing has not started */
459 if ((fsm_getstate(rch
->fsm
) > CH_XID0_PENDING
) ||
460 (fsm_getstate(wch
->fsm
) > CH_XID0_PENDING
)) {
461 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
462 "%s(%s): ABORT - PASSIVE XID",
463 CTCM_FUNTAIL
, dev
->name
);
466 grp
->send_qllc_disc
= 1;
467 fsm_newstate(grp
->fsm
, MPCG_STATE_XID0IOWAIT
);
468 fsm_deltimer(&grp
->timer
);
469 fsm_addtimer(&grp
->timer
, MPC_XID_TIMEOUT_VALUE
,
470 MPCG_EVENT_TIMER
, dev
);
471 grp
->outstanding_xid7
= 0;
472 grp
->outstanding_xid7_p2
= 0;
473 grp
->saved_xid2
= NULL
;
474 if ((rch
->in_mpcgroup
) &&
475 (fsm_getstate(rch
->fsm
) == CH_XID0_PENDING
))
476 fsm_event(grp
->fsm
, MPCG_EVENT_XID0DO
, rch
);
478 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
479 "%s(%s): RX-%s not ready for ACTIVE XID0",
480 CTCM_FUNTAIL
, dev
->name
, rch
->id
);
481 if (grp
->estconnfunc
) {
482 grp
->estconnfunc(grp
->port_num
, -1, 0);
483 grp
->estconnfunc
= NULL
;
485 fsm_deltimer(&grp
->timer
);
488 if ((wch
->in_mpcgroup
) &&
489 (fsm_getstate(wch
->fsm
) == CH_XID0_PENDING
))
490 fsm_event(grp
->fsm
, MPCG_EVENT_XID0DO
, wch
);
492 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
493 "%s(%s): WX-%s not ready for ACTIVE XID0",
494 CTCM_FUNTAIL
, dev
->name
, wch
->id
);
495 if (grp
->estconnfunc
) {
496 grp
->estconnfunc(grp
->port_num
, -1, 0);
497 grp
->estconnfunc
= NULL
;
499 fsm_deltimer(&grp
->timer
);
503 case MPCG_STATE_XID0IOWAIT
:
504 /* already in active XID negotiations */
510 CTCM_PR_DEBUG("Exit %s()\n", __func__
);
513 EXPORT_SYMBOL(ctc_mpc_establish_connectivity
);
517 * (exported interface)
519 void ctc_mpc_dealloc_ch(int port_num
)
521 struct net_device
*dev
;
522 struct ctcm_priv
*priv
;
523 struct mpc_group
*grp
;
525 dev
= ctcmpc_get_dev(port_num
);
531 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_DEBUG
,
532 "%s: %s: refcount = %d\n",
533 CTCM_FUNTAIL
, dev
->name
, netdev_refcnt_read(dev
));
535 fsm_deltimer(&priv
->restart_timer
);
536 grp
->channels_terminating
= 0;
537 fsm_deltimer(&grp
->timer
);
538 grp
->allochanfunc
= NULL
;
539 grp
->estconnfunc
= NULL
;
540 grp
->port_persist
= 0;
541 grp
->send_qllc_disc
= 0;
542 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
547 EXPORT_SYMBOL(ctc_mpc_dealloc_ch
);
550 * ctc_mpc_flow_control
551 * (exported interface)
553 void ctc_mpc_flow_control(int port_num
, int flowc
)
555 struct ctcm_priv
*priv
;
556 struct mpc_group
*grp
;
557 struct net_device
*dev
;
561 dev
= ctcmpc_get_dev(port_num
);
567 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_DEBUG
,
568 "%s: %s: flowc = %d",
569 CTCM_FUNTAIL
, dev
->name
, flowc
);
571 rch
= priv
->channel
[CTCM_READ
];
573 mpcg_state
= fsm_getstate(grp
->fsm
);
576 if (mpcg_state
== MPCG_STATE_FLOWC
)
578 if (mpcg_state
== MPCG_STATE_READY
) {
579 if (grp
->flow_off_called
== 1)
580 grp
->flow_off_called
= 0;
582 fsm_newstate(grp
->fsm
, MPCG_STATE_FLOWC
);
587 if (mpcg_state
== MPCG_STATE_FLOWC
) {
588 fsm_newstate(grp
->fsm
, MPCG_STATE_READY
);
589 /* ensure any data that has accumulated */
590 /* on the io_queue will now be sen t */
591 tasklet_schedule(&rch
->ch_tasklet
);
593 /* possible race condition */
594 if (mpcg_state
== MPCG_STATE_READY
) {
595 grp
->flow_off_called
= 1;
602 EXPORT_SYMBOL(ctc_mpc_flow_control
);
604 static int mpc_send_qllc_discontact(struct net_device
*);
607 * helper function of ctcmpc_unpack_skb
609 static void mpc_rcvd_sweep_resp(struct mpcg_info
*mpcginfo
)
611 struct channel
*rch
= mpcginfo
->ch
;
612 struct net_device
*dev
= rch
->netdev
;
613 struct ctcm_priv
*priv
= dev
->ml_priv
;
614 struct mpc_group
*grp
= priv
->mpcg
;
615 struct channel
*ch
= priv
->channel
[CTCM_WRITE
];
617 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__
, ch
, ch
->id
);
618 CTCM_D3_DUMP((char *)mpcginfo
->sweep
, TH_SWEEP_LENGTH
);
620 grp
->sweep_rsp_pend_num
--;
622 if ((grp
->sweep_req_pend_num
== 0) &&
623 (grp
->sweep_rsp_pend_num
== 0)) {
624 fsm_deltimer(&ch
->sweep_timer
);
626 rch
->th_seq_num
= 0x00;
627 ch
->th_seq_num
= 0x00;
628 ctcm_clear_busy_do(dev
);
636 * helper function of mpc_rcvd_sweep_req
637 * which is a helper of ctcmpc_unpack_skb
639 static void ctcmpc_send_sweep_resp(struct channel
*rch
)
641 struct net_device
*dev
= rch
->netdev
;
642 struct ctcm_priv
*priv
= dev
->ml_priv
;
643 struct mpc_group
*grp
= priv
->mpcg
;
644 struct th_sweep
*header
;
645 struct sk_buff
*sweep_skb
;
646 struct channel
*ch
= priv
->channel
[CTCM_WRITE
];
648 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__
, rch
, rch
->id
);
650 sweep_skb
= __dev_alloc_skb(MPC_BUFSIZE_DEFAULT
, GFP_ATOMIC
| GFP_DMA
);
651 if (sweep_skb
== NULL
) {
652 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
653 "%s(%s): sweep_skb allocation ERROR\n",
654 CTCM_FUNTAIL
, rch
->id
);
658 header
= skb_put_zero(sweep_skb
, TH_SWEEP_LENGTH
);
659 header
->th
.th_ch_flag
= TH_SWEEP_RESP
;
660 header
->sw
.th_last_seq
= ch
->th_seq_num
;
662 netif_trans_update(dev
);
663 skb_queue_tail(&ch
->sweep_queue
, sweep_skb
);
665 fsm_addtimer(&ch
->sweep_timer
, 100, CTC_EVENT_RSWEEP_TIMER
, ch
);
671 ctcm_clear_busy_do(dev
);
672 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
678 * helper function of ctcmpc_unpack_skb
680 static void mpc_rcvd_sweep_req(struct mpcg_info
*mpcginfo
)
682 struct channel
*rch
= mpcginfo
->ch
;
683 struct net_device
*dev
= rch
->netdev
;
684 struct ctcm_priv
*priv
= dev
->ml_priv
;
685 struct mpc_group
*grp
= priv
->mpcg
;
686 struct channel
*ch
= priv
->channel
[CTCM_WRITE
];
689 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_DEBUG
,
690 " %s(): ch=0x%p id=%s\n", __func__
, ch
, ch
->id
);
692 if (grp
->in_sweep
== 0) {
694 ctcm_test_and_set_busy(dev
);
695 grp
->sweep_req_pend_num
= grp
->active_channels
[CTCM_READ
];
696 grp
->sweep_rsp_pend_num
= grp
->active_channels
[CTCM_READ
];
699 CTCM_D3_DUMP((char *)mpcginfo
->sweep
, TH_SWEEP_LENGTH
);
701 grp
->sweep_req_pend_num
--;
702 ctcmpc_send_sweep_resp(ch
);
708 * MPC Group Station FSM definitions
710 static const char *mpcg_event_names
[] = {
711 [MPCG_EVENT_INOP
] = "INOP Condition",
712 [MPCG_EVENT_DISCONC
] = "Discontact Received",
713 [MPCG_EVENT_XID0DO
] = "Channel Active - Start XID",
714 [MPCG_EVENT_XID2
] = "XID2 Received",
715 [MPCG_EVENT_XID2DONE
] = "XID0 Complete",
716 [MPCG_EVENT_XID7DONE
] = "XID7 Complete",
717 [MPCG_EVENT_TIMER
] = "XID Setup Timer",
718 [MPCG_EVENT_DOIO
] = "XID DoIO",
721 static const char *mpcg_state_names
[] = {
722 [MPCG_STATE_RESET
] = "Reset",
723 [MPCG_STATE_INOP
] = "INOP",
724 [MPCG_STATE_XID2INITW
] = "Passive XID- XID0 Pending Start",
725 [MPCG_STATE_XID2INITX
] = "Passive XID- XID0 Pending Complete",
726 [MPCG_STATE_XID7INITW
] = "Passive XID- XID7 Pending P1 Start",
727 [MPCG_STATE_XID7INITX
] = "Passive XID- XID7 Pending P2 Complete",
728 [MPCG_STATE_XID0IOWAIT
] = "Active XID- XID0 Pending Start",
729 [MPCG_STATE_XID0IOWAIX
] = "Active XID- XID0 Pending Complete",
730 [MPCG_STATE_XID7INITI
] = "Active XID- XID7 Pending Start",
731 [MPCG_STATE_XID7INITZ
] = "Active XID- XID7 Pending Complete ",
732 [MPCG_STATE_XID7INITF
] = "XID - XID7 Complete ",
733 [MPCG_STATE_FLOWC
] = "FLOW CONTROL ON",
734 [MPCG_STATE_READY
] = "READY",
738 * The MPC Group Station FSM
741 static const fsm_node mpcg_fsm
[] = {
742 { MPCG_STATE_RESET
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
743 { MPCG_STATE_INOP
, MPCG_EVENT_INOP
, mpc_action_nop
},
744 { MPCG_STATE_FLOWC
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
746 { MPCG_STATE_READY
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
747 { MPCG_STATE_READY
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
749 { MPCG_STATE_XID2INITW
, MPCG_EVENT_XID0DO
, mpc_action_doxid0
},
750 { MPCG_STATE_XID2INITW
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid0
},
751 { MPCG_STATE_XID2INITW
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
752 { MPCG_STATE_XID2INITW
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
753 { MPCG_STATE_XID2INITW
, MPCG_EVENT_DOIO
, mpc_action_yside_xid
},
755 { MPCG_STATE_XID2INITX
, MPCG_EVENT_XID0DO
, mpc_action_doxid0
},
756 { MPCG_STATE_XID2INITX
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid0
},
757 { MPCG_STATE_XID2INITX
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
758 { MPCG_STATE_XID2INITX
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
759 { MPCG_STATE_XID2INITX
, MPCG_EVENT_DOIO
, mpc_action_yside_xid
},
761 { MPCG_STATE_XID7INITW
, MPCG_EVENT_XID2DONE
, mpc_action_doxid7
},
762 { MPCG_STATE_XID7INITW
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
763 { MPCG_STATE_XID7INITW
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid7
},
764 { MPCG_STATE_XID7INITW
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
765 { MPCG_STATE_XID7INITW
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
766 { MPCG_STATE_XID7INITW
, MPCG_EVENT_XID7DONE
, mpc_action_doxid7
},
767 { MPCG_STATE_XID7INITW
, MPCG_EVENT_DOIO
, mpc_action_yside_xid
},
769 { MPCG_STATE_XID7INITX
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
770 { MPCG_STATE_XID7INITX
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid7
},
771 { MPCG_STATE_XID7INITX
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
772 { MPCG_STATE_XID7INITX
, MPCG_EVENT_XID7DONE
, mpc_action_doxid7
},
773 { MPCG_STATE_XID7INITX
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
774 { MPCG_STATE_XID7INITX
, MPCG_EVENT_DOIO
, mpc_action_yside_xid
},
776 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_XID0DO
, mpc_action_doxid0
},
777 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
778 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid0
},
779 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
780 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
781 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_DOIO
, mpc_action_xside_xid
},
783 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_XID0DO
, mpc_action_doxid0
},
784 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
785 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid0
},
786 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
787 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
788 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_DOIO
, mpc_action_xside_xid
},
790 { MPCG_STATE_XID7INITI
, MPCG_EVENT_XID2DONE
, mpc_action_doxid7
},
791 { MPCG_STATE_XID7INITI
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid7
},
792 { MPCG_STATE_XID7INITI
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
793 { MPCG_STATE_XID7INITI
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
794 { MPCG_STATE_XID7INITI
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
795 { MPCG_STATE_XID7INITI
, MPCG_EVENT_XID7DONE
, mpc_action_doxid7
},
796 { MPCG_STATE_XID7INITI
, MPCG_EVENT_DOIO
, mpc_action_xside_xid
},
798 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid7
},
799 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_XID7DONE
, mpc_action_doxid7
},
800 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
801 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
802 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
803 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_DOIO
, mpc_action_xside_xid
},
805 { MPCG_STATE_XID7INITF
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
806 { MPCG_STATE_XID7INITF
, MPCG_EVENT_XID7DONE
, mpc_action_go_ready
},
809 static int mpcg_fsm_len
= ARRAY_SIZE(mpcg_fsm
);
812 * MPC Group Station FSM action
813 * CTCM_PROTO_MPC only
815 static void mpc_action_go_ready(fsm_instance
*fsm
, int event
, void *arg
)
817 struct net_device
*dev
= arg
;
818 struct ctcm_priv
*priv
= dev
->ml_priv
;
819 struct mpc_group
*grp
= priv
->mpcg
;
822 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
823 "%s(%s): No MPC group",
824 CTCM_FUNTAIL
, dev
->name
);
828 fsm_deltimer(&grp
->timer
);
830 if (grp
->saved_xid2
->xid2_flag2
== 0x40) {
831 priv
->xid
->xid2_flag2
= 0x00;
832 if (grp
->estconnfunc
) {
833 grp
->estconnfunc(grp
->port_num
, 1,
834 grp
->group_max_buflen
);
835 grp
->estconnfunc
= NULL
;
836 } else if (grp
->allochanfunc
)
837 grp
->send_qllc_disc
= 1;
839 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
840 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
842 CTCM_FUNTAIL
, dev
->name
);
846 grp
->port_persist
= 1;
847 grp
->out_of_sequence
= 0;
848 grp
->estconn_called
= 0;
850 tasklet_hi_schedule(&grp
->mpc_tasklet2
);
856 * helper of ctcm_init_netdevice
857 * CTCM_PROTO_MPC only
859 void mpc_group_ready(unsigned long adev
)
861 struct net_device
*dev
= (struct net_device
*)adev
;
862 struct ctcm_priv
*priv
= dev
->ml_priv
;
863 struct mpc_group
*grp
= priv
->mpcg
;
864 struct channel
*ch
= NULL
;
867 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
868 "%s(%s): No MPC group",
869 CTCM_FUNTAIL
, dev
->name
);
873 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_NOTICE
,
874 "%s: %s: GROUP TRANSITIONED TO READY, maxbuf = %d\n",
875 CTCM_FUNTAIL
, dev
->name
, grp
->group_max_buflen
);
877 fsm_newstate(grp
->fsm
, MPCG_STATE_READY
);
879 /* Put up a read on the channel */
880 ch
= priv
->channel
[CTCM_READ
];
882 CTCM_PR_DBGDATA("ctcmpc: %s() ToDCM_pdu_seq= %08x\n" ,
883 __func__
, ch
->pdu_seq
);
885 ctcmpc_chx_rxidle(ch
->fsm
, CTC_EVENT_START
, ch
);
886 /* Put the write channel in idle state */
887 ch
= priv
->channel
[CTCM_WRITE
];
888 if (ch
->collect_len
> 0) {
889 spin_lock(&ch
->collect_lock
);
890 ctcm_purge_skb_queue(&ch
->collect_queue
);
892 spin_unlock(&ch
->collect_lock
);
894 ctcm_chx_txidle(ch
->fsm
, CTC_EVENT_START
, ch
);
895 ctcm_clear_busy(dev
);
897 if (grp
->estconnfunc
) {
898 grp
->estconnfunc(grp
->port_num
, 0,
899 grp
->group_max_buflen
);
900 grp
->estconnfunc
= NULL
;
901 } else if (grp
->allochanfunc
) {
902 grp
->allochanfunc(grp
->port_num
, grp
->group_max_buflen
);
905 grp
->send_qllc_disc
= 1;
906 grp
->changed_side
= 0;
913 * Increment the MPC Group Active Channel Counts
914 * helper of dev_action (called from channel fsm)
916 void mpc_channel_action(struct channel
*ch
, int direction
, int action
)
918 struct net_device
*dev
= ch
->netdev
;
919 struct ctcm_priv
*priv
= dev
->ml_priv
;
920 struct mpc_group
*grp
= priv
->mpcg
;
923 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
924 "%s(%s): No MPC group",
925 CTCM_FUNTAIL
, dev
->name
);
929 CTCM_PR_DEBUG("enter %s: ch=0x%p id=%s\n", __func__
, ch
, ch
->id
);
931 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
932 "%s: %i / Grp:%s total_channels=%i, active_channels: "
933 "read=%i, write=%i\n", __func__
, action
,
934 fsm_getstate_str(grp
->fsm
), grp
->num_channel_paths
,
935 grp
->active_channels
[CTCM_READ
],
936 grp
->active_channels
[CTCM_WRITE
]);
938 if ((action
== MPC_CHANNEL_ADD
) && (ch
->in_mpcgroup
== 0)) {
939 grp
->num_channel_paths
++;
940 grp
->active_channels
[direction
]++;
941 grp
->outstanding_xid2
++;
944 if (ch
->xid_skb
!= NULL
)
945 dev_kfree_skb_any(ch
->xid_skb
);
947 ch
->xid_skb
= __dev_alloc_skb(MPC_BUFSIZE_DEFAULT
,
948 GFP_ATOMIC
| GFP_DMA
);
949 if (ch
->xid_skb
== NULL
) {
950 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
951 "%s(%s): Couldn't alloc ch xid_skb\n",
952 CTCM_FUNTAIL
, dev
->name
);
953 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
956 ch
->xid_skb_data
= ch
->xid_skb
->data
;
957 ch
->xid_th
= (struct th_header
*)ch
->xid_skb
->data
;
958 skb_put(ch
->xid_skb
, TH_HEADER_LENGTH
);
959 ch
->xid
= (struct xid2
*)skb_tail_pointer(ch
->xid_skb
);
960 skb_put(ch
->xid_skb
, XID2_LENGTH
);
961 ch
->xid_id
= skb_tail_pointer(ch
->xid_skb
);
962 ch
->xid_skb
->data
= ch
->xid_skb_data
;
963 skb_reset_tail_pointer(ch
->xid_skb
);
964 ch
->xid_skb
->len
= 0;
966 skb_put_data(ch
->xid_skb
, grp
->xid_skb
->data
,
969 ch
->xid
->xid2_dlc_type
=
970 ((CHANNEL_DIRECTION(ch
->flags
) == CTCM_READ
)
971 ? XID2_READ_SIDE
: XID2_WRITE_SIDE
);
973 if (CHANNEL_DIRECTION(ch
->flags
) == CTCM_WRITE
)
974 ch
->xid
->xid2_buf_len
= 0x00;
976 ch
->xid_skb
->data
= ch
->xid_skb_data
;
977 skb_reset_tail_pointer(ch
->xid_skb
);
978 ch
->xid_skb
->len
= 0;
980 fsm_newstate(ch
->fsm
, CH_XID0_PENDING
);
982 if ((grp
->active_channels
[CTCM_READ
] > 0) &&
983 (grp
->active_channels
[CTCM_WRITE
] > 0) &&
984 (fsm_getstate(grp
->fsm
) < MPCG_STATE_XID2INITW
)) {
985 fsm_newstate(grp
->fsm
, MPCG_STATE_XID2INITW
);
986 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_NOTICE
,
987 "%s: %s: MPC GROUP CHANNELS ACTIVE\n",
988 __func__
, dev
->name
);
990 } else if ((action
== MPC_CHANNEL_REMOVE
) &&
991 (ch
->in_mpcgroup
== 1)) {
993 grp
->num_channel_paths
--;
994 grp
->active_channels
[direction
]--;
996 if (ch
->xid_skb
!= NULL
)
997 dev_kfree_skb_any(ch
->xid_skb
);
1000 if (grp
->channels_terminating
)
1003 if (((grp
->active_channels
[CTCM_READ
] == 0) &&
1004 (grp
->active_channels
[CTCM_WRITE
] > 0))
1005 || ((grp
->active_channels
[CTCM_WRITE
] == 0) &&
1006 (grp
->active_channels
[CTCM_READ
] > 0)))
1007 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1010 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_DEBUG
,
1011 "exit %s: %i / Grp:%s total_channels=%i, active_channels: "
1012 "read=%i, write=%i\n", __func__
, action
,
1013 fsm_getstate_str(grp
->fsm
), grp
->num_channel_paths
,
1014 grp
->active_channels
[CTCM_READ
],
1015 grp
->active_channels
[CTCM_WRITE
]);
1017 CTCM_PR_DEBUG("exit %s: ch=0x%p id=%s\n", __func__
, ch
, ch
->id
);
1021 * Unpack a just received skb and hand it over to
1023 * special MPC version of unpack_skb.
1025 * ch The channel where this skb has been received.
1026 * pskb The received skb.
1028 static void ctcmpc_unpack_skb(struct channel
*ch
, struct sk_buff
*pskb
)
1030 struct net_device
*dev
= ch
->netdev
;
1031 struct ctcm_priv
*priv
= dev
->ml_priv
;
1032 struct mpc_group
*grp
= priv
->mpcg
;
1033 struct pdu
*curr_pdu
;
1034 struct mpcg_info
*mpcginfo
;
1035 struct th_header
*header
= NULL
;
1036 struct th_sweep
*sweep
= NULL
;
1037 int pdu_last_seen
= 0;
1039 struct sk_buff
*skb
;
1043 CTCM_PR_DEBUG("ctcmpc enter: %s() %s cp:%i ch:%s\n",
1044 __func__
, dev
->name
, smp_processor_id(), ch
->id
);
1046 header
= (struct th_header
*)pskb
->data
;
1047 if ((header
->th_seg
== 0) &&
1048 (header
->th_ch_flag
== 0) &&
1049 (header
->th_blk_flag
== 0) &&
1050 (header
->th_seq_num
== 0))
1051 /* nothing for us */ goto done
;
1053 CTCM_PR_DBGDATA("%s: th_header\n", __func__
);
1054 CTCM_D3_DUMP((char *)header
, TH_HEADER_LENGTH
);
1055 CTCM_PR_DBGDATA("%s: pskb len: %04x \n", __func__
, pskb
->len
);
1058 pskb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1059 skb_pull(pskb
, TH_HEADER_LENGTH
);
1061 if (likely(header
->th_ch_flag
== TH_HAS_PDU
)) {
1062 CTCM_PR_DBGDATA("%s: came into th_has_pdu\n", __func__
);
1063 if ((fsm_getstate(grp
->fsm
) == MPCG_STATE_FLOWC
) ||
1064 ((fsm_getstate(grp
->fsm
) == MPCG_STATE_READY
) &&
1065 (header
->th_seq_num
!= ch
->th_seq_num
+ 1) &&
1066 (ch
->th_seq_num
!= 0))) {
1067 /* This is NOT the next segment *
1068 * we are not the correct race winner *
1069 * go away and let someone else win *
1070 * BUT..this only applies if xid negot *
1073 grp
->out_of_sequence
+= 1;
1074 __skb_push(pskb
, TH_HEADER_LENGTH
);
1075 skb_queue_tail(&ch
->io_queue
, pskb
);
1076 CTCM_PR_DBGDATA("%s: th_seq_num expect:%08x "
1077 "got:%08x\n", __func__
,
1078 ch
->th_seq_num
+ 1, header
->th_seq_num
);
1082 grp
->out_of_sequence
= 0;
1083 ch
->th_seq_num
= header
->th_seq_num
;
1085 CTCM_PR_DBGDATA("ctcmpc: %s() FromVTAM_th_seq=%08x\n",
1086 __func__
, ch
->th_seq_num
);
1088 if (unlikely(fsm_getstate(grp
->fsm
) != MPCG_STATE_READY
))
1090 while ((pskb
->len
> 0) && !pdu_last_seen
) {
1091 curr_pdu
= (struct pdu
*)pskb
->data
;
1093 CTCM_PR_DBGDATA("%s: pdu_header\n", __func__
);
1094 CTCM_D3_DUMP((char *)pskb
->data
, PDU_HEADER_LENGTH
);
1095 CTCM_PR_DBGDATA("%s: pskb len: %04x \n",
1096 __func__
, pskb
->len
);
1098 skb_pull(pskb
, PDU_HEADER_LENGTH
);
1100 if (curr_pdu
->pdu_flag
& PDU_LAST
)
1102 if (curr_pdu
->pdu_flag
& PDU_CNTL
)
1103 pskb
->protocol
= htons(ETH_P_SNAP
);
1105 pskb
->protocol
= htons(ETH_P_SNA_DIX
);
1107 if ((pskb
->len
<= 0) || (pskb
->len
> ch
->max_bufsize
)) {
1108 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1109 "%s(%s): Dropping packet with "
1111 CTCM_FUNTAIL
, dev
->name
, pskb
->len
);
1113 priv
->stats
.rx_dropped
++;
1114 priv
->stats
.rx_length_errors
++;
1117 skb_reset_mac_header(pskb
);
1118 new_len
= curr_pdu
->pdu_offset
;
1119 CTCM_PR_DBGDATA("%s: new_len: %04x \n",
1121 if ((new_len
== 0) || (new_len
> pskb
->len
)) {
1122 /* should never happen */
1123 /* pskb len must be hosed...bail out */
1124 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1125 "%s(%s): non valid pdu_offset: %04x",
1126 /* "data may be lost", */
1127 CTCM_FUNTAIL
, dev
->name
, new_len
);
1130 skb
= __dev_alloc_skb(new_len
+4, GFP_ATOMIC
);
1133 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1134 "%s(%s): MEMORY allocation error",
1135 CTCM_FUNTAIL
, dev
->name
);
1136 priv
->stats
.rx_dropped
++;
1137 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1140 skb_put_data(skb
, pskb
->data
, new_len
);
1142 skb_reset_mac_header(skb
);
1143 skb
->dev
= pskb
->dev
;
1144 skb
->protocol
= pskb
->protocol
;
1145 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1146 *((__u32
*) skb_push(skb
, 4)) = ch
->pdu_seq
;
1149 if (do_debug_data
) {
1150 ctcm_pr_debug("%s: ToDCM_pdu_seq= %08x\n",
1151 __func__
, ch
->pdu_seq
);
1152 ctcm_pr_debug("%s: skb:%0lx "
1153 "skb len: %d \n", __func__
,
1154 (unsigned long)skb
, skb
->len
);
1155 ctcm_pr_debug("%s: up to 32 bytes "
1156 "of pdu_data sent\n", __func__
);
1157 ctcmpc_dump32((char *)skb
->data
, skb
->len
);
1161 sendrc
= netif_rx(skb
);
1162 priv
->stats
.rx_packets
++;
1163 priv
->stats
.rx_bytes
+= skblen
;
1164 skb_pull(pskb
, new_len
); /* point to next PDU */
1167 mpcginfo
= kmalloc(sizeof(struct mpcg_info
), GFP_ATOMIC
);
1168 if (mpcginfo
== NULL
)
1172 mpcginfo
->th
= header
;
1173 mpcginfo
->skb
= pskb
;
1174 CTCM_PR_DEBUG("%s: Not PDU - may be control pkt\n",
1177 sweep
= (struct th_sweep
*)pskb
->data
;
1178 mpcginfo
->sweep
= sweep
;
1179 if (header
->th_ch_flag
== TH_SWEEP_REQ
)
1180 mpc_rcvd_sweep_req(mpcginfo
);
1181 else if (header
->th_ch_flag
== TH_SWEEP_RESP
)
1182 mpc_rcvd_sweep_resp(mpcginfo
);
1183 else if (header
->th_blk_flag
== TH_DATA_IS_XID
) {
1184 struct xid2
*thisxid
= (struct xid2
*)pskb
->data
;
1185 skb_pull(pskb
, XID2_LENGTH
);
1186 mpcginfo
->xid
= thisxid
;
1187 fsm_event(grp
->fsm
, MPCG_EVENT_XID2
, mpcginfo
);
1188 } else if (header
->th_blk_flag
== TH_DISCONTACT
)
1189 fsm_event(grp
->fsm
, MPCG_EVENT_DISCONC
, mpcginfo
);
1190 else if (header
->th_seq_num
!= 0) {
1191 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1192 "%s(%s): control pkt expected\n",
1193 CTCM_FUNTAIL
, dev
->name
);
1194 priv
->stats
.rx_dropped
++;
1195 /* mpcginfo only used for non-data transfers */
1197 ctcmpc_dump_skb(pskb
, -8);
1203 dev_kfree_skb_any(pskb
);
1204 if (sendrc
== NET_RX_DROP
) {
1206 "The network backlog for %s is exceeded, "
1207 "package dropped\n", __func__
);
1208 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1211 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1212 __func__
, dev
->name
, ch
, ch
->id
);
1216 * tasklet helper for mpc's skb unpacking.
1218 * ch The channel to work on.
1219 * Allow flow control back pressure to occur here.
1220 * Throttling back channel can result in excessive
1221 * channel inactivity and system deact of channel
1223 void ctcmpc_bh(unsigned long thischan
)
1225 struct channel
*ch
= (struct channel
*)thischan
;
1226 struct sk_buff
*skb
;
1227 struct net_device
*dev
= ch
->netdev
;
1228 struct ctcm_priv
*priv
= dev
->ml_priv
;
1229 struct mpc_group
*grp
= priv
->mpcg
;
1231 CTCM_PR_DEBUG("%s cp:%i enter: %s() %s\n",
1232 dev
->name
, smp_processor_id(), __func__
, ch
->id
);
1233 /* caller has requested driver to throttle back */
1234 while ((fsm_getstate(grp
->fsm
) != MPCG_STATE_FLOWC
) &&
1235 (skb
= skb_dequeue(&ch
->io_queue
))) {
1236 ctcmpc_unpack_skb(ch
, skb
);
1237 if (grp
->out_of_sequence
> 20) {
1238 /* assume data loss has occurred if */
1239 /* missing seq_num for extended */
1240 /* period of time */
1241 grp
->out_of_sequence
= 0;
1242 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1245 if (skb
== skb_peek(&ch
->io_queue
))
1248 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1249 __func__
, dev
->name
, ch
, ch
->id
);
1254 * MPC Group Initializations
1256 struct mpc_group
*ctcmpc_init_mpc_group(struct ctcm_priv
*priv
)
1258 struct mpc_group
*grp
;
1260 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_INFO
,
1261 "Enter %s(%p)", CTCM_FUNTAIL
, priv
);
1263 grp
= kzalloc(sizeof(struct mpc_group
), GFP_KERNEL
);
1267 grp
->fsm
= init_fsm("mpcg", mpcg_state_names
, mpcg_event_names
,
1268 MPCG_NR_STATES
, MPCG_NR_EVENTS
, mpcg_fsm
,
1269 mpcg_fsm_len
, GFP_KERNEL
);
1270 if (grp
->fsm
== NULL
) {
1275 fsm_newstate(grp
->fsm
, MPCG_STATE_RESET
);
1276 fsm_settimer(grp
->fsm
, &grp
->timer
);
1279 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT
, GFP_ATOMIC
| GFP_DMA
);
1280 if (grp
->xid_skb
== NULL
) {
1281 kfree_fsm(grp
->fsm
);
1285 /* base xid for all channels in group */
1286 grp
->xid_skb_data
= grp
->xid_skb
->data
;
1287 grp
->xid_th
= (struct th_header
*)grp
->xid_skb
->data
;
1288 skb_put_data(grp
->xid_skb
, &thnorm
, TH_HEADER_LENGTH
);
1290 grp
->xid
= (struct xid2
*)skb_tail_pointer(grp
->xid_skb
);
1291 skb_put_data(grp
->xid_skb
, &init_xid
, XID2_LENGTH
);
1292 grp
->xid
->xid2_adj_id
= jiffies
| 0xfff00000;
1293 grp
->xid
->xid2_sender_id
= jiffies
;
1295 grp
->xid_id
= skb_tail_pointer(grp
->xid_skb
);
1296 skb_put_data(grp
->xid_skb
, "VTAM", 4);
1299 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT
, GFP_ATOMIC
|GFP_DMA
);
1300 if (grp
->rcvd_xid_skb
== NULL
) {
1301 kfree_fsm(grp
->fsm
);
1302 dev_kfree_skb(grp
->xid_skb
);
1306 grp
->rcvd_xid_data
= grp
->rcvd_xid_skb
->data
;
1307 grp
->rcvd_xid_th
= (struct th_header
*)grp
->rcvd_xid_skb
->data
;
1308 skb_put_data(grp
->rcvd_xid_skb
, &thnorm
, TH_HEADER_LENGTH
);
1309 grp
->saved_xid2
= NULL
;
1310 priv
->xid
= grp
->xid
;
1316 * The MPC Group Station FSM
1320 * MPC Group Station FSM actions
1321 * CTCM_PROTO_MPC only
1325 * NOP action for statemachines
1327 static void mpc_action_nop(fsm_instance
*fi
, int event
, void *arg
)
1332 * invoked when the device transitions to dev_stopped
1333 * MPC will stop each individual channel if a single XID failure
1334 * occurs, or will intitiate all channels be stopped if a GROUP
1335 * level failure occurs.
1337 static void mpc_action_go_inop(fsm_instance
*fi
, int event
, void *arg
)
1339 struct net_device
*dev
= arg
;
1340 struct ctcm_priv
*priv
;
1341 struct mpc_group
*grp
;
1342 struct channel
*wch
;
1344 CTCM_PR_DEBUG("Enter %s: %s\n", __func__
, dev
->name
);
1346 priv
= dev
->ml_priv
;
1348 grp
->flow_off_called
= 0;
1349 fsm_deltimer(&grp
->timer
);
1350 if (grp
->channels_terminating
)
1353 grp
->channels_terminating
= 1;
1354 grp
->saved_state
= fsm_getstate(grp
->fsm
);
1355 fsm_newstate(grp
->fsm
, MPCG_STATE_INOP
);
1356 if (grp
->saved_state
> MPCG_STATE_XID7INITF
)
1357 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
1358 "%s(%s): MPC GROUP INOPERATIVE",
1359 CTCM_FUNTAIL
, dev
->name
);
1360 if ((grp
->saved_state
!= MPCG_STATE_RESET
) ||
1361 /* dealloc_channel has been called */
1362 (grp
->port_persist
== 0))
1363 fsm_deltimer(&priv
->restart_timer
);
1365 wch
= priv
->channel
[CTCM_WRITE
];
1367 switch (grp
->saved_state
) {
1368 case MPCG_STATE_RESET
:
1369 case MPCG_STATE_INOP
:
1370 case MPCG_STATE_XID2INITW
:
1371 case MPCG_STATE_XID0IOWAIT
:
1372 case MPCG_STATE_XID2INITX
:
1373 case MPCG_STATE_XID7INITW
:
1374 case MPCG_STATE_XID7INITX
:
1375 case MPCG_STATE_XID0IOWAIX
:
1376 case MPCG_STATE_XID7INITI
:
1377 case MPCG_STATE_XID7INITZ
:
1378 case MPCG_STATE_XID7INITF
:
1380 case MPCG_STATE_FLOWC
:
1381 case MPCG_STATE_READY
:
1383 tasklet_hi_schedule(&wch
->ch_disc_tasklet
);
1386 grp
->xid2_tgnum
= 0;
1387 grp
->group_max_buflen
= 0; /*min of all received */
1388 grp
->outstanding_xid2
= 0;
1389 grp
->outstanding_xid7
= 0;
1390 grp
->outstanding_xid7_p2
= 0;
1391 grp
->saved_xid2
= NULL
;
1393 grp
->changed_side
= 0;
1395 grp
->rcvd_xid_skb
->data
= grp
->rcvd_xid_data
;
1396 skb_reset_tail_pointer(grp
->rcvd_xid_skb
);
1397 grp
->rcvd_xid_skb
->len
= 0;
1398 grp
->rcvd_xid_th
= (struct th_header
*)grp
->rcvd_xid_skb
->data
;
1399 skb_put_data(grp
->rcvd_xid_skb
, &thnorm
, TH_HEADER_LENGTH
);
1401 if (grp
->send_qllc_disc
== 1) {
1402 grp
->send_qllc_disc
= 0;
1403 mpc_send_qllc_discontact(dev
);
1406 /* DO NOT issue DEV_EVENT_STOP directly out of this code */
1407 /* This can result in INOP of VTAM PU due to halting of */
1408 /* outstanding IO which causes a sense to be returned */
1409 /* Only about 3 senses are allowed and then IOS/VTAM will*/
1410 /* become unreachable without manual intervention */
1411 if ((grp
->port_persist
== 1) || (grp
->alloc_called
)) {
1412 grp
->alloc_called
= 0;
1413 fsm_deltimer(&priv
->restart_timer
);
1414 fsm_addtimer(&priv
->restart_timer
, 500, DEV_EVENT_RESTART
, dev
);
1415 fsm_newstate(grp
->fsm
, MPCG_STATE_RESET
);
1416 if (grp
->saved_state
> MPCG_STATE_XID7INITF
)
1417 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_ALWAYS
,
1418 "%s(%s): MPC GROUP RECOVERY SCHEDULED",
1419 CTCM_FUNTAIL
, dev
->name
);
1421 fsm_deltimer(&priv
->restart_timer
);
1422 fsm_addtimer(&priv
->restart_timer
, 500, DEV_EVENT_STOP
, dev
);
1423 fsm_newstate(grp
->fsm
, MPCG_STATE_RESET
);
1424 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_ALWAYS
,
1425 "%s(%s): NO MPC GROUP RECOVERY ATTEMPTED",
1426 CTCM_FUNTAIL
, dev
->name
);
1431 * Handle mpc group action timeout.
1432 * MPC Group Station FSM action
1433 * CTCM_PROTO_MPC only
1435 * fi An instance of an mpc_group fsm.
1436 * event The event, just happened.
1437 * arg Generic pointer, casted from net_device * upon call.
1439 static void mpc_action_timeout(fsm_instance
*fi
, int event
, void *arg
)
1441 struct net_device
*dev
= arg
;
1442 struct ctcm_priv
*priv
;
1443 struct mpc_group
*grp
;
1444 struct channel
*wch
;
1445 struct channel
*rch
;
1447 priv
= dev
->ml_priv
;
1449 wch
= priv
->channel
[CTCM_WRITE
];
1450 rch
= priv
->channel
[CTCM_READ
];
1452 switch (fsm_getstate(grp
->fsm
)) {
1453 case MPCG_STATE_XID2INITW
:
1454 /* Unless there is outstanding IO on the */
1455 /* channel just return and wait for ATTN */
1456 /* interrupt to begin XID negotiations */
1457 if ((fsm_getstate(rch
->fsm
) == CH_XID0_PENDING
) &&
1458 (fsm_getstate(wch
->fsm
) == CH_XID0_PENDING
))
1462 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1465 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_DEBUG
,
1467 CTCM_FUNTAIL
, dev
->name
);
1472 * MPC Group Station FSM action
1473 * CTCM_PROTO_MPC only
1475 void mpc_action_discontact(fsm_instance
*fi
, int event
, void *arg
)
1477 struct mpcg_info
*mpcginfo
= arg
;
1478 struct channel
*ch
= mpcginfo
->ch
;
1479 struct net_device
*dev
;
1480 struct ctcm_priv
*priv
;
1481 struct mpc_group
*grp
;
1486 priv
= dev
->ml_priv
;
1488 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
1490 CTCM_FUNTAIL
, dev
->name
, ch
->id
);
1492 grp
->send_qllc_disc
= 1;
1493 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1502 * MPC Group Station - not part of FSM
1503 * CTCM_PROTO_MPC only
1504 * called from add_channel in ctcm_main.c
1506 void mpc_action_send_discontact(unsigned long thischan
)
1509 struct channel
*ch
= (struct channel
*)thischan
;
1510 unsigned long saveflags
= 0;
1512 spin_lock_irqsave(get_ccwdev_lock(ch
->cdev
), saveflags
);
1513 rc
= ccw_device_start(ch
->cdev
, &ch
->ccw
[15], 0, 0xff, 0);
1514 spin_unlock_irqrestore(get_ccwdev_lock(ch
->cdev
), saveflags
);
1517 ctcm_ccw_check_rc(ch
, rc
, (char *)__func__
);
1525 * helper function of mpc FSM
1526 * CTCM_PROTO_MPC only
1527 * mpc_action_rcvd_xid7
1529 static int mpc_validate_xid(struct mpcg_info
*mpcginfo
)
1531 struct channel
*ch
= mpcginfo
->ch
;
1532 struct net_device
*dev
= ch
->netdev
;
1533 struct ctcm_priv
*priv
= dev
->ml_priv
;
1534 struct mpc_group
*grp
= priv
->mpcg
;
1535 struct xid2
*xid
= mpcginfo
->xid
;
1539 int len
= TH_HEADER_LENGTH
+ PDU_HEADER_LENGTH
;
1541 CTCM_PR_DEBUG("Enter %s: xid=%p\n", __func__
, xid
);
1545 /* XID REJECTED: xid == NULL */
1546 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1547 "%s(%s): xid = NULL",
1548 CTCM_FUNTAIL
, ch
->id
);
1552 CTCM_D3_DUMP((char *)xid
, XID2_LENGTH
);
1554 /*the received direction should be the opposite of ours */
1555 if (((CHANNEL_DIRECTION(ch
->flags
) == CTCM_READ
) ? XID2_WRITE_SIDE
:
1556 XID2_READ_SIDE
) != xid
->xid2_dlc_type
) {
1558 /* XID REJECTED: r/w channel pairing mismatch */
1559 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1560 "%s(%s): r/w channel pairing mismatch",
1561 CTCM_FUNTAIL
, ch
->id
);
1565 if (xid
->xid2_dlc_type
== XID2_READ_SIDE
) {
1566 CTCM_PR_DEBUG("%s: grpmaxbuf:%d xid2buflen:%d\n", __func__
,
1567 grp
->group_max_buflen
, xid
->xid2_buf_len
);
1569 if (grp
->group_max_buflen
== 0 || grp
->group_max_buflen
>
1570 xid
->xid2_buf_len
- len
)
1571 grp
->group_max_buflen
= xid
->xid2_buf_len
- len
;
1574 if (grp
->saved_xid2
== NULL
) {
1576 (struct xid2
*)skb_tail_pointer(grp
->rcvd_xid_skb
);
1578 skb_put_data(grp
->rcvd_xid_skb
, xid
, XID2_LENGTH
);
1579 grp
->rcvd_xid_skb
->data
= grp
->rcvd_xid_data
;
1581 skb_reset_tail_pointer(grp
->rcvd_xid_skb
);
1582 grp
->rcvd_xid_skb
->len
= 0;
1584 /* convert two 32 bit numbers into 1 64 bit for id compare */
1585 our_id
= (__u64
)priv
->xid
->xid2_adj_id
;
1586 our_id
= our_id
<< 32;
1587 our_id
= our_id
+ priv
->xid
->xid2_sender_id
;
1588 their_id
= (__u64
)xid
->xid2_adj_id
;
1589 their_id
= their_id
<< 32;
1590 their_id
= their_id
+ xid
->xid2_sender_id
;
1591 /* lower id assume the xside role */
1592 if (our_id
< their_id
) {
1594 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
1595 "%s(%s): WE HAVE LOW ID - TAKE XSIDE",
1596 CTCM_FUNTAIL
, ch
->id
);
1599 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
1600 "%s(%s): WE HAVE HIGH ID - TAKE YSIDE",
1601 CTCM_FUNTAIL
, ch
->id
);
1605 if (xid
->xid2_flag4
!= grp
->saved_xid2
->xid2_flag4
) {
1607 /* XID REJECTED: xid flag byte4 mismatch */
1608 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1609 "%s(%s): xid flag byte4 mismatch",
1610 CTCM_FUNTAIL
, ch
->id
);
1612 if (xid
->xid2_flag2
== 0x40) {
1614 /* XID REJECTED - xid NOGOOD */
1615 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1616 "%s(%s): xid NOGOOD",
1617 CTCM_FUNTAIL
, ch
->id
);
1619 if (xid
->xid2_adj_id
!= grp
->saved_xid2
->xid2_adj_id
) {
1621 /* XID REJECTED - Adjacent Station ID Mismatch */
1622 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1623 "%s(%s): Adjacent Station ID Mismatch",
1624 CTCM_FUNTAIL
, ch
->id
);
1626 if (xid
->xid2_sender_id
!= grp
->saved_xid2
->xid2_sender_id
) {
1628 /* XID REJECTED - Sender Address Mismatch */
1629 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1630 "%s(%s): Sender Address Mismatch",
1631 CTCM_FUNTAIL
, ch
->id
);
1637 "The XID used in the MPC protocol is not valid, "
1639 priv
->xid
->xid2_flag2
= 0x40;
1640 grp
->saved_xid2
->xid2_flag2
= 0x40;
1647 * MPC Group Station FSM action
1648 * CTCM_PROTO_MPC only
1650 static void mpc_action_side_xid(fsm_instance
*fsm
, void *arg
, int side
)
1652 struct channel
*ch
= arg
;
1655 unsigned long saveflags
= 0; /* avoids compiler warning with
1656 spin_unlock_irqrestore */
1658 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1659 __func__
, smp_processor_id(), ch
, ch
->id
);
1661 if (ctcm_checkalloc_buffer(ch
))
1665 * skb data-buffer referencing:
1667 ch
->trans_skb
->data
= ch
->trans_skb_data
;
1668 skb_reset_tail_pointer(ch
->trans_skb
);
1669 ch
->trans_skb
->len
= 0;
1670 /* result of the previous 3 statements is NOT always
1671 * already set after ctcm_checkalloc_buffer
1672 * because of possible reuse of the trans_skb
1674 memset(ch
->trans_skb
->data
, 0, 16);
1675 ch
->rcvd_xid_th
= (struct th_header
*)ch
->trans_skb_data
;
1676 /* check is main purpose here: */
1677 skb_put(ch
->trans_skb
, TH_HEADER_LENGTH
);
1678 ch
->rcvd_xid
= (struct xid2
*)skb_tail_pointer(ch
->trans_skb
);
1679 /* check is main purpose here: */
1680 skb_put(ch
->trans_skb
, XID2_LENGTH
);
1681 ch
->rcvd_xid_id
= skb_tail_pointer(ch
->trans_skb
);
1682 /* cleanup back to startpoint */
1683 ch
->trans_skb
->data
= ch
->trans_skb_data
;
1684 skb_reset_tail_pointer(ch
->trans_skb
);
1685 ch
->trans_skb
->len
= 0;
1687 /* non-checking rewrite of above skb data-buffer referencing: */
1689 memset(ch->trans_skb->data, 0, 16);
1690 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1691 ch->rcvd_xid = (struct xid2 *)(ch->trans_skb_data + TH_HEADER_LENGTH);
1692 ch->rcvd_xid_id = ch->trans_skb_data + TH_HEADER_LENGTH + XID2_LENGTH;
1695 ch
->ccw
[8].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1696 ch
->ccw
[8].count
= 0;
1697 ch
->ccw
[8].cda
= 0x00;
1699 if (!(ch
->xid_th
&& ch
->xid
&& ch
->xid_id
))
1700 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_INFO
,
1701 "%s(%s): xid_th=%p, xid=%p, xid_id=%p",
1702 CTCM_FUNTAIL
, ch
->id
, ch
->xid_th
, ch
->xid
, ch
->xid_id
);
1704 if (side
== XSIDE
) {
1705 /* mpc_action_xside_xid */
1706 if (ch
->xid_th
== NULL
)
1708 ch
->ccw
[9].cmd_code
= CCW_CMD_WRITE
;
1709 ch
->ccw
[9].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1710 ch
->ccw
[9].count
= TH_HEADER_LENGTH
;
1711 ch
->ccw
[9].cda
= virt_to_dma32(ch
->xid_th
);
1713 if (ch
->xid
== NULL
)
1715 ch
->ccw
[10].cmd_code
= CCW_CMD_WRITE
;
1716 ch
->ccw
[10].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1717 ch
->ccw
[10].count
= XID2_LENGTH
;
1718 ch
->ccw
[10].cda
= virt_to_dma32(ch
->xid
);
1720 ch
->ccw
[11].cmd_code
= CCW_CMD_READ
;
1721 ch
->ccw
[11].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1722 ch
->ccw
[11].count
= TH_HEADER_LENGTH
;
1723 ch
->ccw
[11].cda
= virt_to_dma32(ch
->rcvd_xid_th
);
1725 ch
->ccw
[12].cmd_code
= CCW_CMD_READ
;
1726 ch
->ccw
[12].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1727 ch
->ccw
[12].count
= XID2_LENGTH
;
1728 ch
->ccw
[12].cda
= virt_to_dma32(ch
->rcvd_xid
);
1730 ch
->ccw
[13].cmd_code
= CCW_CMD_READ
;
1731 ch
->ccw
[13].cda
= virt_to_dma32(ch
->rcvd_xid_id
);
1733 } else { /* side == YSIDE : mpc_action_yside_xid */
1734 ch
->ccw
[9].cmd_code
= CCW_CMD_READ
;
1735 ch
->ccw
[9].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1736 ch
->ccw
[9].count
= TH_HEADER_LENGTH
;
1737 ch
->ccw
[9].cda
= virt_to_dma32(ch
->rcvd_xid_th
);
1739 ch
->ccw
[10].cmd_code
= CCW_CMD_READ
;
1740 ch
->ccw
[10].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1741 ch
->ccw
[10].count
= XID2_LENGTH
;
1742 ch
->ccw
[10].cda
= virt_to_dma32(ch
->rcvd_xid
);
1744 if (ch
->xid_th
== NULL
)
1746 ch
->ccw
[11].cmd_code
= CCW_CMD_WRITE
;
1747 ch
->ccw
[11].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1748 ch
->ccw
[11].count
= TH_HEADER_LENGTH
;
1749 ch
->ccw
[11].cda
= virt_to_dma32(ch
->xid_th
);
1751 if (ch
->xid
== NULL
)
1753 ch
->ccw
[12].cmd_code
= CCW_CMD_WRITE
;
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_dma32(ch
->xid
);
1758 if (ch
->xid_id
== NULL
)
1760 ch
->ccw
[13].cmd_code
= CCW_CMD_WRITE
;
1761 ch
->ccw
[13].cda
= virt_to_dma32(ch
->xid_id
);
1764 ch
->ccw
[13].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1765 ch
->ccw
[13].count
= 4;
1767 ch
->ccw
[14].cmd_code
= CCW_CMD_NOOP
;
1768 ch
->ccw
[14].flags
= CCW_FLAG_SLI
;
1769 ch
->ccw
[14].count
= 0;
1770 ch
->ccw
[14].cda
= 0;
1772 CTCM_CCW_DUMP((char *)&ch
->ccw
[8], sizeof(struct ccw1
) * 7);
1773 CTCM_D3_DUMP((char *)ch
->xid_th
, TH_HEADER_LENGTH
);
1774 CTCM_D3_DUMP((char *)ch
->xid
, XID2_LENGTH
);
1775 CTCM_D3_DUMP((char *)ch
->xid_id
, 4);
1777 if (!in_hardirq()) {
1778 /* Such conditional locking is a known problem for
1779 * sparse because its static undeterministic.
1780 * Warnings should be ignored here. */
1781 spin_lock_irqsave(get_ccwdev_lock(ch
->cdev
), saveflags
);
1785 fsm_addtimer(&ch
->timer
, 5000 , CTC_EVENT_TIMER
, ch
);
1786 rc
= ccw_device_start(ch
->cdev
, &ch
->ccw
[8], 0, 0xff, 0);
1788 if (gotlock
) /* see remark above about conditional locking */
1789 spin_unlock_irqrestore(get_ccwdev_lock(ch
->cdev
), saveflags
);
1792 ctcm_ccw_check_rc(ch
, rc
,
1793 (side
== XSIDE
) ? "x-side XID" : "y-side XID");
1797 CTCM_PR_DEBUG("Exit %s: ch=0x%p id=%s\n",
1798 __func__
, ch
, ch
->id
);
1804 * MPC Group Station FSM action
1805 * CTCM_PROTO_MPC only
1807 static void mpc_action_xside_xid(fsm_instance
*fsm
, int event
, void *arg
)
1809 mpc_action_side_xid(fsm
, arg
, XSIDE
);
1813 * MPC Group Station FSM action
1814 * CTCM_PROTO_MPC only
1816 static void mpc_action_yside_xid(fsm_instance
*fsm
, int event
, void *arg
)
1818 mpc_action_side_xid(fsm
, arg
, YSIDE
);
1822 * MPC Group Station FSM action
1823 * CTCM_PROTO_MPC only
1825 static void mpc_action_doxid0(fsm_instance
*fsm
, int event
, void *arg
)
1827 struct channel
*ch
= arg
;
1828 struct net_device
*dev
= ch
->netdev
;
1829 struct ctcm_priv
*priv
= dev
->ml_priv
;
1830 struct mpc_group
*grp
= priv
->mpcg
;
1832 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1833 __func__
, smp_processor_id(), ch
, ch
->id
);
1835 if (ch
->xid
== NULL
) {
1836 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1837 "%s(%s): ch->xid == NULL",
1838 CTCM_FUNTAIL
, dev
->name
);
1842 fsm_newstate(ch
->fsm
, CH_XID0_INPROGRESS
);
1844 ch
->xid
->xid2_option
= XID2_0
;
1846 switch (fsm_getstate(grp
->fsm
)) {
1847 case MPCG_STATE_XID2INITW
:
1848 case MPCG_STATE_XID2INITX
:
1849 ch
->ccw
[8].cmd_code
= CCW_CMD_SENSE_CMD
;
1851 case MPCG_STATE_XID0IOWAIT
:
1852 case MPCG_STATE_XID0IOWAIX
:
1853 ch
->ccw
[8].cmd_code
= CCW_CMD_WRITE_CTL
;
1857 fsm_event(grp
->fsm
, MPCG_EVENT_DOIO
, ch
);
1863 * MPC Group Station FSM action
1864 * CTCM_PROTO_MPC only
1866 static void mpc_action_doxid7(fsm_instance
*fsm
, int event
, void *arg
)
1868 struct net_device
*dev
= arg
;
1869 struct ctcm_priv
*priv
= dev
->ml_priv
;
1870 struct mpc_group
*grp
= NULL
;
1879 for (direction
= CTCM_READ
; direction
<= CTCM_WRITE
; direction
++) {
1880 struct channel
*ch
= priv
->channel
[direction
];
1881 struct xid2
*thisxid
= ch
->xid
;
1882 ch
->xid_skb
->data
= ch
->xid_skb_data
;
1883 skb_reset_tail_pointer(ch
->xid_skb
);
1884 ch
->xid_skb
->len
= 0;
1885 thisxid
->xid2_option
= XID2_7
;
1889 if (grp
->outstanding_xid7_p2
> 0) {
1890 if (grp
->roll
== YSIDE
) {
1891 if (fsm_getstate(ch
->fsm
) == CH_XID7_PENDING1
) {
1892 fsm_newstate(ch
->fsm
, CH_XID7_PENDING2
);
1893 ch
->ccw
[8].cmd_code
= CCW_CMD_SENSE_CMD
;
1894 skb_put_data(ch
->xid_skb
, &thdummy
,
1898 } else if (fsm_getstate(ch
->fsm
) < CH_XID7_PENDING2
) {
1899 fsm_newstate(ch
->fsm
, CH_XID7_PENDING2
);
1900 ch
->ccw
[8].cmd_code
= CCW_CMD_WRITE_CTL
;
1901 skb_put_data(ch
->xid_skb
, &thnorm
,
1907 if (grp
->roll
== YSIDE
) {
1908 if (fsm_getstate(ch
->fsm
) < CH_XID7_PENDING4
) {
1909 fsm_newstate(ch
->fsm
, CH_XID7_PENDING4
);
1910 skb_put_data(ch
->xid_skb
, &thnorm
,
1912 ch
->ccw
[8].cmd_code
= CCW_CMD_WRITE_CTL
;
1915 } else if (fsm_getstate(ch
->fsm
) == CH_XID7_PENDING3
) {
1916 fsm_newstate(ch
->fsm
, CH_XID7_PENDING4
);
1917 ch
->ccw
[8].cmd_code
= CCW_CMD_SENSE_CMD
;
1918 skb_put_data(ch
->xid_skb
, &thdummy
,
1925 fsm_event(grp
->fsm
, MPCG_EVENT_DOIO
, ch
);
1932 * MPC Group Station FSM action
1933 * CTCM_PROTO_MPC only
1935 static void mpc_action_rcvd_xid0(fsm_instance
*fsm
, int event
, void *arg
)
1938 struct mpcg_info
*mpcginfo
= arg
;
1939 struct channel
*ch
= mpcginfo
->ch
;
1940 struct net_device
*dev
= ch
->netdev
;
1941 struct ctcm_priv
*priv
= dev
->ml_priv
;
1942 struct mpc_group
*grp
= priv
->mpcg
;
1944 CTCM_PR_DEBUG("%s: ch-id:%s xid2:%i xid7:%i xidt_p2:%i \n",
1945 __func__
, ch
->id
, grp
->outstanding_xid2
,
1946 grp
->outstanding_xid7
, grp
->outstanding_xid7_p2
);
1948 if (fsm_getstate(ch
->fsm
) < CH_XID7_PENDING
)
1949 fsm_newstate(ch
->fsm
, CH_XID7_PENDING
);
1951 grp
->outstanding_xid2
--;
1952 grp
->outstanding_xid7
++;
1953 grp
->outstanding_xid7_p2
++;
1955 /* must change state before validating xid to */
1956 /* properly handle interim interrupts received*/
1957 switch (fsm_getstate(grp
->fsm
)) {
1958 case MPCG_STATE_XID2INITW
:
1959 fsm_newstate(grp
->fsm
, MPCG_STATE_XID2INITX
);
1960 mpc_validate_xid(mpcginfo
);
1962 case MPCG_STATE_XID0IOWAIT
:
1963 fsm_newstate(grp
->fsm
, MPCG_STATE_XID0IOWAIX
);
1964 mpc_validate_xid(mpcginfo
);
1966 case MPCG_STATE_XID2INITX
:
1967 if (grp
->outstanding_xid2
== 0) {
1968 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITW
);
1969 mpc_validate_xid(mpcginfo
);
1970 fsm_event(grp
->fsm
, MPCG_EVENT_XID2DONE
, dev
);
1973 case MPCG_STATE_XID0IOWAIX
:
1974 if (grp
->outstanding_xid2
== 0) {
1975 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITI
);
1976 mpc_validate_xid(mpcginfo
);
1977 fsm_event(grp
->fsm
, MPCG_EVENT_XID2DONE
, dev
);
1982 CTCM_PR_DEBUG("ctcmpc:%s() %s xid2:%i xid7:%i xidt_p2:%i \n",
1983 __func__
, ch
->id
, grp
->outstanding_xid2
,
1984 grp
->outstanding_xid7
, grp
->outstanding_xid7_p2
);
1985 CTCM_PR_DEBUG("ctcmpc:%s() %s grpstate: %s chanstate: %s \n",
1987 fsm_getstate_str(grp
->fsm
), fsm_getstate_str(ch
->fsm
));
1994 * MPC Group Station FSM action
1995 * CTCM_PROTO_MPC only
1997 static void mpc_action_rcvd_xid7(fsm_instance
*fsm
, int event
, void *arg
)
1999 struct mpcg_info
*mpcginfo
= arg
;
2000 struct channel
*ch
= mpcginfo
->ch
;
2001 struct net_device
*dev
= ch
->netdev
;
2002 struct ctcm_priv
*priv
= dev
->ml_priv
;
2003 struct mpc_group
*grp
= priv
->mpcg
;
2005 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
2006 __func__
, smp_processor_id(), ch
, ch
->id
);
2007 CTCM_PR_DEBUG("%s: outstanding_xid7: %i, outstanding_xid7_p2: %i\n",
2008 __func__
, grp
->outstanding_xid7
, grp
->outstanding_xid7_p2
);
2010 grp
->outstanding_xid7
--;
2011 ch
->xid_skb
->data
= ch
->xid_skb_data
;
2012 skb_reset_tail_pointer(ch
->xid_skb
);
2013 ch
->xid_skb
->len
= 0;
2015 switch (fsm_getstate(grp
->fsm
)) {
2016 case MPCG_STATE_XID7INITI
:
2017 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITZ
);
2018 mpc_validate_xid(mpcginfo
);
2020 case MPCG_STATE_XID7INITW
:
2021 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITX
);
2022 mpc_validate_xid(mpcginfo
);
2024 case MPCG_STATE_XID7INITZ
:
2025 case MPCG_STATE_XID7INITX
:
2026 if (grp
->outstanding_xid7
== 0) {
2027 if (grp
->outstanding_xid7_p2
> 0) {
2028 grp
->outstanding_xid7
=
2029 grp
->outstanding_xid7_p2
;
2030 grp
->outstanding_xid7_p2
= 0;
2032 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITF
);
2034 mpc_validate_xid(mpcginfo
);
2035 fsm_event(grp
->fsm
, MPCG_EVENT_XID7DONE
, dev
);
2038 mpc_validate_xid(mpcginfo
);
2045 * mpc_action helper of an MPC Group Station FSM action
2046 * CTCM_PROTO_MPC only
2048 static int mpc_send_qllc_discontact(struct net_device
*dev
)
2050 struct sk_buff
*skb
;
2051 struct qllc
*qllcptr
;
2052 struct ctcm_priv
*priv
= dev
->ml_priv
;
2053 struct mpc_group
*grp
= priv
->mpcg
;
2055 CTCM_PR_DEBUG("%s: GROUP STATE: %s\n",
2056 __func__
, mpcg_state_names
[grp
->saved_state
]);
2058 switch (grp
->saved_state
) {
2060 * establish conn callback function is
2061 * preferred method to report failure
2063 case MPCG_STATE_XID0IOWAIT
:
2064 case MPCG_STATE_XID0IOWAIX
:
2065 case MPCG_STATE_XID7INITI
:
2066 case MPCG_STATE_XID7INITZ
:
2067 case MPCG_STATE_XID2INITW
:
2068 case MPCG_STATE_XID2INITX
:
2069 case MPCG_STATE_XID7INITW
:
2070 case MPCG_STATE_XID7INITX
:
2071 if (grp
->estconnfunc
) {
2072 grp
->estconnfunc(grp
->port_num
, -1, 0);
2073 grp
->estconnfunc
= NULL
;
2077 case MPCG_STATE_FLOWC
:
2078 case MPCG_STATE_READY
:
2079 grp
->send_qllc_disc
= 2;
2081 skb
= __dev_alloc_skb(sizeof(struct qllc
), GFP_ATOMIC
);
2083 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
2084 "%s(%s): skb allocation error",
2085 CTCM_FUNTAIL
, dev
->name
);
2086 priv
->stats
.rx_dropped
++;
2090 qllcptr
= skb_put(skb
, sizeof(struct qllc
));
2091 qllcptr
->qllc_address
= 0xcc;
2092 qllcptr
->qllc_commands
= 0x03;
2094 if (skb_headroom(skb
) < 4) {
2095 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
2096 "%s(%s): skb_headroom error",
2097 CTCM_FUNTAIL
, dev
->name
);
2098 dev_kfree_skb_any(skb
);
2102 *((__u32
*)skb_push(skb
, 4)) =
2103 priv
->channel
[CTCM_READ
]->pdu_seq
;
2104 priv
->channel
[CTCM_READ
]->pdu_seq
++;
2105 CTCM_PR_DBGDATA("ctcmpc: %s ToDCM_pdu_seq= %08x\n",
2106 __func__
, priv
->channel
[CTCM_READ
]->pdu_seq
);
2108 /* receipt of CC03 resets anticipated sequence number on
2110 priv
->channel
[CTCM_READ
]->pdu_seq
= 0x00;
2111 skb_reset_mac_header(skb
);
2113 skb
->protocol
= htons(ETH_P_SNAP
);
2114 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2116 CTCM_D3_DUMP(skb
->data
, (sizeof(struct qllc
) + 4));
2127 /* --- This is the END my friend --- */