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];
135 char bhex
[82], duphex
[82];
144 for (ct
= 0; ct
< len
; ct
++, ptr
++, rptr
++) {
146 sprintf(addr
, "%16.16llx", (__u64
)rptr
);
148 sprintf(boff
, "%4.4X", (__u32
)ct
);
152 if ((sw
== 4) || (sw
== 12))
157 sprintf(tbuf
, "%2.2llX", (__u64
)*ptr
);
161 if ((0 != isprint(*ptr
)) && (*ptr
>= 0x20))
171 if ((strcmp(duphex
, bhex
)) != 0) {
174 "Duplicate as above to %s", addr
);
175 ctcm_pr_debug(" --- %s ---\n",
178 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
179 addr
, boff
, bhex
, basc
);
181 strcpy(duphex
, bhex
);
190 for ( ; rm
> 0; rm
--, sw
++) {
191 if ((sw
== 4) || (sw
== 12))
199 sprintf(tdup
, "Duplicate as above to %s", addr
);
200 ctcm_pr_debug(" --- %s ---\n", tdup
);
202 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
203 addr
, boff
, bhex
, basc
);
206 sprintf(tdup
, "Duplicate as above to %s", addr
);
207 ctcm_pr_debug(" --- %s ---\n", tdup
);
210 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
211 addr
, boff
, bhex
, basc
);
217 } /* end of ctcmpc_dumpit */
222 * Dump header and first 16 bytes of an sk_buff for debugging purposes.
224 * skb The sk_buff to dump.
225 * offset Offset relative to skb-data, where to start the dump.
227 void ctcmpc_dump_skb(struct sk_buff
*skb
, int offset
)
230 struct th_header
*header
;
239 header
= (struct th_header
*)p
;
241 ctcm_pr_debug("dump:\n");
242 ctcm_pr_debug("skb len=%d \n", skb
->len
);
244 switch (header
->th_ch_flag
) {
249 if ((header
->th_blk_flag
== TH_DATA_IS_XID
) &&
250 (header
->th_is_xid
== 0x01))
260 pheader
= (struct pdu
*)p
;
261 ctcm_pr_debug("pdu->offset: %d hex: %04x\n",
262 pheader
->pdu_offset
, pheader
->pdu_offset
);
263 ctcm_pr_debug("pdu->flag : %02x\n", pheader
->pdu_flag
);
264 ctcm_pr_debug("pdu->proto : %02x\n", pheader
->pdu_proto
);
265 ctcm_pr_debug("pdu->seq : %02x\n", pheader
->pdu_seq
);
269 ctcm_pr_debug("th->seg : %02x\n", header
->th_seg
);
270 ctcm_pr_debug("th->ch : %02x\n", header
->th_ch_flag
);
271 ctcm_pr_debug("th->blk_flag: %02x\n", header
->th_blk_flag
);
272 ctcm_pr_debug("th->type : %s\n",
273 (header
->th_is_xid
) ? "DATA" : "XID");
274 ctcm_pr_debug("th->seqnum : %04x\n", header
->th_seq_num
);
280 ctcm_pr_debug("data: ");
281 for (i
= 0; i
< bl
; i
++)
282 ctcm_pr_debug("%02x%s", *p
++, (i
% 16) ? " " : "\n");
287 static struct net_device
*ctcmpc_get_dev(int port_num
)
290 struct net_device
*dev
;
291 struct ctcm_priv
*priv
;
293 sprintf(device
, "%s%i", MPC_DEVICE_NAME
, port_num
);
295 dev
= __dev_get_by_name(&init_net
, device
);
298 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
299 "%s: Device not found by name: %s",
300 CTCM_FUNTAIL
, device
);
305 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
306 "%s(%s): dev->ml_priv is NULL",
307 CTCM_FUNTAIL
, device
);
310 if (priv
->mpcg
== NULL
) {
311 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
312 "%s(%s): priv->mpcg is NULL",
313 CTCM_FUNTAIL
, device
);
320 * ctc_mpc_alloc_channel
321 * (exported interface)
323 * Device Initialization :
324 * ACTPATH driven IO operations
326 int ctc_mpc_alloc_channel(int port_num
, void (*callback
)(int, int))
328 struct net_device
*dev
;
329 struct mpc_group
*grp
;
330 struct ctcm_priv
*priv
;
332 dev
= ctcmpc_get_dev(port_num
);
338 grp
->allochanfunc
= callback
;
339 grp
->port_num
= port_num
;
340 grp
->port_persist
= 1;
342 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_INFO
,
344 CTCM_FUNTAIL
, dev
->name
, fsm_getstate_str(grp
->fsm
));
346 switch (fsm_getstate(grp
->fsm
)) {
347 case MPCG_STATE_INOP
:
348 /* Group is in the process of terminating */
349 grp
->alloc_called
= 1;
351 case MPCG_STATE_RESET
:
352 /* MPC Group will transition to state */
353 /* MPCG_STATE_XID2INITW iff the minimum number */
354 /* of 1 read and 1 write channel have successfully*/
356 /*fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);*/
358 grp
->send_qllc_disc
= 1;
359 case MPCG_STATE_XID0IOWAIT
:
360 fsm_deltimer(&grp
->timer
);
361 grp
->outstanding_xid2
= 0;
362 grp
->outstanding_xid7
= 0;
363 grp
->outstanding_xid7_p2
= 0;
364 grp
->saved_xid2
= NULL
;
367 fsm_event(priv
->fsm
, DEV_EVENT_START
, dev
);
369 case MPCG_STATE_READY
:
370 /* XID exchanges completed after PORT was activated */
371 /* Link station already active */
372 /* Maybe timing issue...retry callback */
373 grp
->allocchan_callback_retries
++;
374 if (grp
->allocchan_callback_retries
< 4) {
375 if (grp
->allochanfunc
)
376 grp
->allochanfunc(grp
->port_num
,
377 grp
->group_max_buflen
);
379 /* there are problems...bail out */
380 /* there may be a state mismatch so restart */
381 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
382 grp
->allocchan_callback_retries
= 0;
389 EXPORT_SYMBOL(ctc_mpc_alloc_channel
);
392 * ctc_mpc_establish_connectivity
393 * (exported interface)
395 void ctc_mpc_establish_connectivity(int port_num
,
396 void (*callback
)(int, int, int))
398 struct net_device
*dev
;
399 struct mpc_group
*grp
;
400 struct ctcm_priv
*priv
;
401 struct channel
*rch
, *wch
;
403 dev
= ctcmpc_get_dev(port_num
);
408 rch
= priv
->channel
[CTCM_READ
];
409 wch
= priv
->channel
[CTCM_WRITE
];
411 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_INFO
,
413 CTCM_FUNTAIL
, dev
->name
, fsm_getstate_str(grp
->fsm
));
415 grp
->estconnfunc
= callback
;
416 grp
->port_num
= port_num
;
418 switch (fsm_getstate(grp
->fsm
)) {
419 case MPCG_STATE_READY
:
420 /* XID exchanges completed after PORT was activated */
421 /* Link station already active */
422 /* Maybe timing issue...retry callback */
423 fsm_deltimer(&grp
->timer
);
424 grp
->estconn_callback_retries
++;
425 if (grp
->estconn_callback_retries
< 4) {
426 if (grp
->estconnfunc
) {
427 grp
->estconnfunc(grp
->port_num
, 0,
428 grp
->group_max_buflen
);
429 grp
->estconnfunc
= NULL
;
432 /* there are problems...bail out */
433 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
434 grp
->estconn_callback_retries
= 0;
437 case MPCG_STATE_INOP
:
438 case MPCG_STATE_RESET
:
439 /* MPC Group is not ready to start XID - min num of */
440 /* 1 read and 1 write channel have not been acquired*/
442 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
443 "%s(%s): REJECTED - inactive channels",
444 CTCM_FUNTAIL
, dev
->name
);
445 if (grp
->estconnfunc
) {
446 grp
->estconnfunc(grp
->port_num
, -1, 0);
447 grp
->estconnfunc
= NULL
;
450 case MPCG_STATE_XID2INITW
:
451 /* alloc channel was called but no XID exchange */
452 /* has occurred. initiate xside XID exchange */
453 /* make sure yside XID0 processing has not started */
455 if ((fsm_getstate(rch
->fsm
) > CH_XID0_PENDING
) ||
456 (fsm_getstate(wch
->fsm
) > CH_XID0_PENDING
)) {
457 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
458 "%s(%s): ABORT - PASSIVE XID",
459 CTCM_FUNTAIL
, dev
->name
);
462 grp
->send_qllc_disc
= 1;
463 fsm_newstate(grp
->fsm
, MPCG_STATE_XID0IOWAIT
);
464 fsm_deltimer(&grp
->timer
);
465 fsm_addtimer(&grp
->timer
, MPC_XID_TIMEOUT_VALUE
,
466 MPCG_EVENT_TIMER
, dev
);
467 grp
->outstanding_xid7
= 0;
468 grp
->outstanding_xid7_p2
= 0;
469 grp
->saved_xid2
= NULL
;
470 if ((rch
->in_mpcgroup
) &&
471 (fsm_getstate(rch
->fsm
) == CH_XID0_PENDING
))
472 fsm_event(grp
->fsm
, MPCG_EVENT_XID0DO
, rch
);
474 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
475 "%s(%s): RX-%s not ready for ACTIVE XID0",
476 CTCM_FUNTAIL
, dev
->name
, rch
->id
);
477 if (grp
->estconnfunc
) {
478 grp
->estconnfunc(grp
->port_num
, -1, 0);
479 grp
->estconnfunc
= NULL
;
481 fsm_deltimer(&grp
->timer
);
484 if ((wch
->in_mpcgroup
) &&
485 (fsm_getstate(wch
->fsm
) == CH_XID0_PENDING
))
486 fsm_event(grp
->fsm
, MPCG_EVENT_XID0DO
, wch
);
488 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
489 "%s(%s): WX-%s not ready for ACTIVE XID0",
490 CTCM_FUNTAIL
, dev
->name
, wch
->id
);
491 if (grp
->estconnfunc
) {
492 grp
->estconnfunc(grp
->port_num
, -1, 0);
493 grp
->estconnfunc
= NULL
;
495 fsm_deltimer(&grp
->timer
);
499 case MPCG_STATE_XID0IOWAIT
:
500 /* already in active XID negotiations */
506 CTCM_PR_DEBUG("Exit %s()\n", __func__
);
509 EXPORT_SYMBOL(ctc_mpc_establish_connectivity
);
513 * (exported interface)
515 void ctc_mpc_dealloc_ch(int port_num
)
517 struct net_device
*dev
;
518 struct ctcm_priv
*priv
;
519 struct mpc_group
*grp
;
521 dev
= ctcmpc_get_dev(port_num
);
527 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_DEBUG
,
528 "%s: %s: refcount = %d\n",
529 CTCM_FUNTAIL
, dev
->name
, netdev_refcnt_read(dev
));
531 fsm_deltimer(&priv
->restart_timer
);
532 grp
->channels_terminating
= 0;
533 fsm_deltimer(&grp
->timer
);
534 grp
->allochanfunc
= NULL
;
535 grp
->estconnfunc
= NULL
;
536 grp
->port_persist
= 0;
537 grp
->send_qllc_disc
= 0;
538 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
543 EXPORT_SYMBOL(ctc_mpc_dealloc_ch
);
546 * ctc_mpc_flow_control
547 * (exported interface)
549 void ctc_mpc_flow_control(int port_num
, int flowc
)
551 struct ctcm_priv
*priv
;
552 struct mpc_group
*grp
;
553 struct net_device
*dev
;
557 dev
= ctcmpc_get_dev(port_num
);
563 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_DEBUG
,
564 "%s: %s: flowc = %d",
565 CTCM_FUNTAIL
, dev
->name
, flowc
);
567 rch
= priv
->channel
[CTCM_READ
];
569 mpcg_state
= fsm_getstate(grp
->fsm
);
572 if (mpcg_state
== MPCG_STATE_FLOWC
)
574 if (mpcg_state
== MPCG_STATE_READY
) {
575 if (grp
->flow_off_called
== 1)
576 grp
->flow_off_called
= 0;
578 fsm_newstate(grp
->fsm
, MPCG_STATE_FLOWC
);
583 if (mpcg_state
== MPCG_STATE_FLOWC
) {
584 fsm_newstate(grp
->fsm
, MPCG_STATE_READY
);
585 /* ensure any data that has accumulated */
586 /* on the io_queue will now be sen t */
587 tasklet_schedule(&rch
->ch_tasklet
);
589 /* possible race condition */
590 if (mpcg_state
== MPCG_STATE_READY
) {
591 grp
->flow_off_called
= 1;
598 EXPORT_SYMBOL(ctc_mpc_flow_control
);
600 static int mpc_send_qllc_discontact(struct net_device
*);
603 * helper function of ctcmpc_unpack_skb
605 static void mpc_rcvd_sweep_resp(struct mpcg_info
*mpcginfo
)
607 struct channel
*rch
= mpcginfo
->ch
;
608 struct net_device
*dev
= rch
->netdev
;
609 struct ctcm_priv
*priv
= dev
->ml_priv
;
610 struct mpc_group
*grp
= priv
->mpcg
;
611 struct channel
*ch
= priv
->channel
[CTCM_WRITE
];
613 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__
, ch
, ch
->id
);
614 CTCM_D3_DUMP((char *)mpcginfo
->sweep
, TH_SWEEP_LENGTH
);
616 grp
->sweep_rsp_pend_num
--;
618 if ((grp
->sweep_req_pend_num
== 0) &&
619 (grp
->sweep_rsp_pend_num
== 0)) {
620 fsm_deltimer(&ch
->sweep_timer
);
622 rch
->th_seq_num
= 0x00;
623 ch
->th_seq_num
= 0x00;
624 ctcm_clear_busy_do(dev
);
634 * helper function of mpc_rcvd_sweep_req
635 * which is a helper of ctcmpc_unpack_skb
637 static void ctcmpc_send_sweep_resp(struct channel
*rch
)
639 struct net_device
*dev
= rch
->netdev
;
640 struct ctcm_priv
*priv
= dev
->ml_priv
;
641 struct mpc_group
*grp
= priv
->mpcg
;
642 struct th_sweep
*header
;
643 struct sk_buff
*sweep_skb
;
644 struct channel
*ch
= priv
->channel
[CTCM_WRITE
];
646 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__
, rch
, rch
->id
);
648 sweep_skb
= __dev_alloc_skb(MPC_BUFSIZE_DEFAULT
, GFP_ATOMIC
| GFP_DMA
);
649 if (sweep_skb
== NULL
) {
650 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
651 "%s(%s): sweep_skb allocation ERROR\n",
652 CTCM_FUNTAIL
, rch
->id
);
656 header
= kmalloc(sizeof(struct th_sweep
), gfp_type());
659 dev_kfree_skb_any(sweep_skb
);
663 header
->th
.th_seg
= 0x00 ;
664 header
->th
.th_ch_flag
= TH_SWEEP_RESP
;
665 header
->th
.th_blk_flag
= 0x00;
666 header
->th
.th_is_xid
= 0x00;
667 header
->th
.th_seq_num
= 0x00;
668 header
->sw
.th_last_seq
= ch
->th_seq_num
;
670 memcpy(skb_put(sweep_skb
, TH_SWEEP_LENGTH
), header
, TH_SWEEP_LENGTH
);
674 dev
->trans_start
= jiffies
;
675 skb_queue_tail(&ch
->sweep_queue
, sweep_skb
);
677 fsm_addtimer(&ch
->sweep_timer
, 100, CTC_EVENT_RSWEEP_TIMER
, ch
);
683 ctcm_clear_busy_do(dev
);
684 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
690 * helper function of ctcmpc_unpack_skb
692 static void mpc_rcvd_sweep_req(struct mpcg_info
*mpcginfo
)
694 struct channel
*rch
= mpcginfo
->ch
;
695 struct net_device
*dev
= rch
->netdev
;
696 struct ctcm_priv
*priv
= dev
->ml_priv
;
697 struct mpc_group
*grp
= priv
->mpcg
;
698 struct channel
*ch
= priv
->channel
[CTCM_WRITE
];
701 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_DEBUG
,
702 " %s(): ch=0x%p id=%s\n", __func__
, ch
, ch
->id
);
704 if (grp
->in_sweep
== 0) {
706 ctcm_test_and_set_busy(dev
);
707 grp
->sweep_req_pend_num
= grp
->active_channels
[CTCM_READ
];
708 grp
->sweep_rsp_pend_num
= grp
->active_channels
[CTCM_READ
];
711 CTCM_D3_DUMP((char *)mpcginfo
->sweep
, TH_SWEEP_LENGTH
);
713 grp
->sweep_req_pend_num
--;
714 ctcmpc_send_sweep_resp(ch
);
720 * MPC Group Station FSM definitions
722 static const char *mpcg_event_names
[] = {
723 [MPCG_EVENT_INOP
] = "INOP Condition",
724 [MPCG_EVENT_DISCONC
] = "Discontact Received",
725 [MPCG_EVENT_XID0DO
] = "Channel Active - Start XID",
726 [MPCG_EVENT_XID2
] = "XID2 Received",
727 [MPCG_EVENT_XID2DONE
] = "XID0 Complete",
728 [MPCG_EVENT_XID7DONE
] = "XID7 Complete",
729 [MPCG_EVENT_TIMER
] = "XID Setup Timer",
730 [MPCG_EVENT_DOIO
] = "XID DoIO",
733 static const char *mpcg_state_names
[] = {
734 [MPCG_STATE_RESET
] = "Reset",
735 [MPCG_STATE_INOP
] = "INOP",
736 [MPCG_STATE_XID2INITW
] = "Passive XID- XID0 Pending Start",
737 [MPCG_STATE_XID2INITX
] = "Passive XID- XID0 Pending Complete",
738 [MPCG_STATE_XID7INITW
] = "Passive XID- XID7 Pending P1 Start",
739 [MPCG_STATE_XID7INITX
] = "Passive XID- XID7 Pending P2 Complete",
740 [MPCG_STATE_XID0IOWAIT
] = "Active XID- XID0 Pending Start",
741 [MPCG_STATE_XID0IOWAIX
] = "Active XID- XID0 Pending Complete",
742 [MPCG_STATE_XID7INITI
] = "Active XID- XID7 Pending Start",
743 [MPCG_STATE_XID7INITZ
] = "Active XID- XID7 Pending Complete ",
744 [MPCG_STATE_XID7INITF
] = "XID - XID7 Complete ",
745 [MPCG_STATE_FLOWC
] = "FLOW CONTROL ON",
746 [MPCG_STATE_READY
] = "READY",
750 * The MPC Group Station FSM
753 static const fsm_node mpcg_fsm
[] = {
754 { MPCG_STATE_RESET
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
755 { MPCG_STATE_INOP
, MPCG_EVENT_INOP
, mpc_action_nop
},
756 { MPCG_STATE_FLOWC
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
758 { MPCG_STATE_READY
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
759 { MPCG_STATE_READY
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
761 { MPCG_STATE_XID2INITW
, MPCG_EVENT_XID0DO
, mpc_action_doxid0
},
762 { MPCG_STATE_XID2INITW
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid0
},
763 { MPCG_STATE_XID2INITW
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
764 { MPCG_STATE_XID2INITW
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
765 { MPCG_STATE_XID2INITW
, MPCG_EVENT_DOIO
, mpc_action_yside_xid
},
767 { MPCG_STATE_XID2INITX
, MPCG_EVENT_XID0DO
, mpc_action_doxid0
},
768 { MPCG_STATE_XID2INITX
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid0
},
769 { MPCG_STATE_XID2INITX
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
770 { MPCG_STATE_XID2INITX
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
771 { MPCG_STATE_XID2INITX
, MPCG_EVENT_DOIO
, mpc_action_yside_xid
},
773 { MPCG_STATE_XID7INITW
, MPCG_EVENT_XID2DONE
, mpc_action_doxid7
},
774 { MPCG_STATE_XID7INITW
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
775 { MPCG_STATE_XID7INITW
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid7
},
776 { MPCG_STATE_XID7INITW
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
777 { MPCG_STATE_XID7INITW
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
778 { MPCG_STATE_XID7INITW
, MPCG_EVENT_XID7DONE
, mpc_action_doxid7
},
779 { MPCG_STATE_XID7INITW
, MPCG_EVENT_DOIO
, mpc_action_yside_xid
},
781 { MPCG_STATE_XID7INITX
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
782 { MPCG_STATE_XID7INITX
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid7
},
783 { MPCG_STATE_XID7INITX
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
784 { MPCG_STATE_XID7INITX
, MPCG_EVENT_XID7DONE
, mpc_action_doxid7
},
785 { MPCG_STATE_XID7INITX
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
786 { MPCG_STATE_XID7INITX
, MPCG_EVENT_DOIO
, mpc_action_yside_xid
},
788 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_XID0DO
, mpc_action_doxid0
},
789 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
790 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid0
},
791 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
792 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
793 { MPCG_STATE_XID0IOWAIT
, MPCG_EVENT_DOIO
, mpc_action_xside_xid
},
795 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_XID0DO
, mpc_action_doxid0
},
796 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
797 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid0
},
798 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
799 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
800 { MPCG_STATE_XID0IOWAIX
, MPCG_EVENT_DOIO
, mpc_action_xside_xid
},
802 { MPCG_STATE_XID7INITI
, MPCG_EVENT_XID2DONE
, mpc_action_doxid7
},
803 { MPCG_STATE_XID7INITI
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid7
},
804 { MPCG_STATE_XID7INITI
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
805 { MPCG_STATE_XID7INITI
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
806 { MPCG_STATE_XID7INITI
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
807 { MPCG_STATE_XID7INITI
, MPCG_EVENT_XID7DONE
, mpc_action_doxid7
},
808 { MPCG_STATE_XID7INITI
, MPCG_EVENT_DOIO
, mpc_action_xside_xid
},
810 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_XID2
, mpc_action_rcvd_xid7
},
811 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_XID7DONE
, mpc_action_doxid7
},
812 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_DISCONC
, mpc_action_discontact
},
813 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
814 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_TIMER
, mpc_action_timeout
},
815 { MPCG_STATE_XID7INITZ
, MPCG_EVENT_DOIO
, mpc_action_xside_xid
},
817 { MPCG_STATE_XID7INITF
, MPCG_EVENT_INOP
, mpc_action_go_inop
},
818 { MPCG_STATE_XID7INITF
, MPCG_EVENT_XID7DONE
, mpc_action_go_ready
},
821 static int mpcg_fsm_len
= ARRAY_SIZE(mpcg_fsm
);
824 * MPC Group Station FSM action
825 * CTCM_PROTO_MPC only
827 static void mpc_action_go_ready(fsm_instance
*fsm
, int event
, void *arg
)
829 struct net_device
*dev
= arg
;
830 struct ctcm_priv
*priv
= dev
->ml_priv
;
831 struct mpc_group
*grp
= priv
->mpcg
;
834 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
835 "%s(%s): No MPC group",
836 CTCM_FUNTAIL
, dev
->name
);
840 fsm_deltimer(&grp
->timer
);
842 if (grp
->saved_xid2
->xid2_flag2
== 0x40) {
843 priv
->xid
->xid2_flag2
= 0x00;
844 if (grp
->estconnfunc
) {
845 grp
->estconnfunc(grp
->port_num
, 1,
846 grp
->group_max_buflen
);
847 grp
->estconnfunc
= NULL
;
848 } else if (grp
->allochanfunc
)
849 grp
->send_qllc_disc
= 1;
851 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
852 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
854 CTCM_FUNTAIL
, dev
->name
);
858 grp
->port_persist
= 1;
859 grp
->out_of_sequence
= 0;
860 grp
->estconn_called
= 0;
862 tasklet_hi_schedule(&grp
->mpc_tasklet2
);
868 * helper of ctcm_init_netdevice
869 * CTCM_PROTO_MPC only
871 void mpc_group_ready(unsigned long adev
)
873 struct net_device
*dev
= (struct net_device
*)adev
;
874 struct ctcm_priv
*priv
= dev
->ml_priv
;
875 struct mpc_group
*grp
= priv
->mpcg
;
876 struct channel
*ch
= NULL
;
879 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
880 "%s(%s): No MPC group",
881 CTCM_FUNTAIL
, dev
->name
);
885 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_NOTICE
,
886 "%s: %s: GROUP TRANSITIONED TO READY, maxbuf = %d\n",
887 CTCM_FUNTAIL
, dev
->name
, grp
->group_max_buflen
);
889 fsm_newstate(grp
->fsm
, MPCG_STATE_READY
);
891 /* Put up a read on the channel */
892 ch
= priv
->channel
[CTCM_READ
];
894 CTCM_PR_DBGDATA("ctcmpc: %s() ToDCM_pdu_seq= %08x\n" ,
895 __func__
, ch
->pdu_seq
);
897 ctcmpc_chx_rxidle(ch
->fsm
, CTC_EVENT_START
, ch
);
898 /* Put the write channel in idle state */
899 ch
= priv
->channel
[CTCM_WRITE
];
900 if (ch
->collect_len
> 0) {
901 spin_lock(&ch
->collect_lock
);
902 ctcm_purge_skb_queue(&ch
->collect_queue
);
904 spin_unlock(&ch
->collect_lock
);
906 ctcm_chx_txidle(ch
->fsm
, CTC_EVENT_START
, ch
);
907 ctcm_clear_busy(dev
);
909 if (grp
->estconnfunc
) {
910 grp
->estconnfunc(grp
->port_num
, 0,
911 grp
->group_max_buflen
);
912 grp
->estconnfunc
= NULL
;
913 } else if (grp
->allochanfunc
)
914 grp
->allochanfunc(grp
->port_num
, grp
->group_max_buflen
);
916 grp
->send_qllc_disc
= 1;
917 grp
->changed_side
= 0;
924 * Increment the MPC Group Active Channel Counts
925 * helper of dev_action (called from channel fsm)
927 void mpc_channel_action(struct channel
*ch
, int direction
, int action
)
929 struct net_device
*dev
= ch
->netdev
;
930 struct ctcm_priv
*priv
= dev
->ml_priv
;
931 struct mpc_group
*grp
= priv
->mpcg
;
934 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
935 "%s(%s): No MPC group",
936 CTCM_FUNTAIL
, dev
->name
);
940 CTCM_PR_DEBUG("enter %s: ch=0x%p id=%s\n", __func__
, ch
, ch
->id
);
942 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
943 "%s: %i / Grp:%s total_channels=%i, active_channels: "
944 "read=%i, write=%i\n", __func__
, action
,
945 fsm_getstate_str(grp
->fsm
), grp
->num_channel_paths
,
946 grp
->active_channels
[CTCM_READ
],
947 grp
->active_channels
[CTCM_WRITE
]);
949 if ((action
== MPC_CHANNEL_ADD
) && (ch
->in_mpcgroup
== 0)) {
950 grp
->num_channel_paths
++;
951 grp
->active_channels
[direction
]++;
952 grp
->outstanding_xid2
++;
955 if (ch
->xid_skb
!= NULL
)
956 dev_kfree_skb_any(ch
->xid_skb
);
958 ch
->xid_skb
= __dev_alloc_skb(MPC_BUFSIZE_DEFAULT
,
959 GFP_ATOMIC
| GFP_DMA
);
960 if (ch
->xid_skb
== NULL
) {
961 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
962 "%s(%s): Couldn't alloc ch xid_skb\n",
963 CTCM_FUNTAIL
, dev
->name
);
964 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
967 ch
->xid_skb_data
= ch
->xid_skb
->data
;
968 ch
->xid_th
= (struct th_header
*)ch
->xid_skb
->data
;
969 skb_put(ch
->xid_skb
, TH_HEADER_LENGTH
);
970 ch
->xid
= (struct xid2
*)skb_tail_pointer(ch
->xid_skb
);
971 skb_put(ch
->xid_skb
, XID2_LENGTH
);
972 ch
->xid_id
= skb_tail_pointer(ch
->xid_skb
);
973 ch
->xid_skb
->data
= ch
->xid_skb_data
;
974 skb_reset_tail_pointer(ch
->xid_skb
);
975 ch
->xid_skb
->len
= 0;
977 memcpy(skb_put(ch
->xid_skb
, grp
->xid_skb
->len
),
981 ch
->xid
->xid2_dlc_type
=
982 ((CHANNEL_DIRECTION(ch
->flags
) == CTCM_READ
)
983 ? XID2_READ_SIDE
: XID2_WRITE_SIDE
);
985 if (CHANNEL_DIRECTION(ch
->flags
) == CTCM_WRITE
)
986 ch
->xid
->xid2_buf_len
= 0x00;
988 ch
->xid_skb
->data
= ch
->xid_skb_data
;
989 skb_reset_tail_pointer(ch
->xid_skb
);
990 ch
->xid_skb
->len
= 0;
992 fsm_newstate(ch
->fsm
, CH_XID0_PENDING
);
994 if ((grp
->active_channels
[CTCM_READ
] > 0) &&
995 (grp
->active_channels
[CTCM_WRITE
] > 0) &&
996 (fsm_getstate(grp
->fsm
) < MPCG_STATE_XID2INITW
)) {
997 fsm_newstate(grp
->fsm
, MPCG_STATE_XID2INITW
);
998 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_NOTICE
,
999 "%s: %s: MPC GROUP CHANNELS ACTIVE\n",
1000 __func__
, dev
->name
);
1002 } else if ((action
== MPC_CHANNEL_REMOVE
) &&
1003 (ch
->in_mpcgroup
== 1)) {
1004 ch
->in_mpcgroup
= 0;
1005 grp
->num_channel_paths
--;
1006 grp
->active_channels
[direction
]--;
1008 if (ch
->xid_skb
!= NULL
)
1009 dev_kfree_skb_any(ch
->xid_skb
);
1012 if (grp
->channels_terminating
)
1015 if (((grp
->active_channels
[CTCM_READ
] == 0) &&
1016 (grp
->active_channels
[CTCM_WRITE
] > 0))
1017 || ((grp
->active_channels
[CTCM_WRITE
] == 0) &&
1018 (grp
->active_channels
[CTCM_READ
] > 0)))
1019 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1022 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_DEBUG
,
1023 "exit %s: %i / Grp:%s total_channels=%i, active_channels: "
1024 "read=%i, write=%i\n", __func__
, action
,
1025 fsm_getstate_str(grp
->fsm
), grp
->num_channel_paths
,
1026 grp
->active_channels
[CTCM_READ
],
1027 grp
->active_channels
[CTCM_WRITE
]);
1029 CTCM_PR_DEBUG("exit %s: ch=0x%p id=%s\n", __func__
, ch
, ch
->id
);
1033 * Unpack a just received skb and hand it over to
1035 * special MPC version of unpack_skb.
1037 * ch The channel where this skb has been received.
1038 * pskb The received skb.
1040 static void ctcmpc_unpack_skb(struct channel
*ch
, struct sk_buff
*pskb
)
1042 struct net_device
*dev
= ch
->netdev
;
1043 struct ctcm_priv
*priv
= dev
->ml_priv
;
1044 struct mpc_group
*grp
= priv
->mpcg
;
1045 struct pdu
*curr_pdu
;
1046 struct mpcg_info
*mpcginfo
;
1047 struct th_header
*header
= NULL
;
1048 struct th_sweep
*sweep
= NULL
;
1049 int pdu_last_seen
= 0;
1051 struct sk_buff
*skb
;
1055 CTCM_PR_DEBUG("ctcmpc enter: %s() %s cp:%i ch:%s\n",
1056 __func__
, dev
->name
, smp_processor_id(), ch
->id
);
1058 header
= (struct th_header
*)pskb
->data
;
1059 if ((header
->th_seg
== 0) &&
1060 (header
->th_ch_flag
== 0) &&
1061 (header
->th_blk_flag
== 0) &&
1062 (header
->th_seq_num
== 0))
1063 /* nothing for us */ goto done
;
1065 CTCM_PR_DBGDATA("%s: th_header\n", __func__
);
1066 CTCM_D3_DUMP((char *)header
, TH_HEADER_LENGTH
);
1067 CTCM_PR_DBGDATA("%s: pskb len: %04x \n", __func__
, pskb
->len
);
1070 pskb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1071 skb_pull(pskb
, TH_HEADER_LENGTH
);
1073 if (likely(header
->th_ch_flag
== TH_HAS_PDU
)) {
1074 CTCM_PR_DBGDATA("%s: came into th_has_pdu\n", __func__
);
1075 if ((fsm_getstate(grp
->fsm
) == MPCG_STATE_FLOWC
) ||
1076 ((fsm_getstate(grp
->fsm
) == MPCG_STATE_READY
) &&
1077 (header
->th_seq_num
!= ch
->th_seq_num
+ 1) &&
1078 (ch
->th_seq_num
!= 0))) {
1079 /* This is NOT the next segment *
1080 * we are not the correct race winner *
1081 * go away and let someone else win *
1082 * BUT..this only applies if xid negot *
1085 grp
->out_of_sequence
+= 1;
1086 __skb_push(pskb
, TH_HEADER_LENGTH
);
1087 skb_queue_tail(&ch
->io_queue
, pskb
);
1088 CTCM_PR_DBGDATA("%s: th_seq_num expect:%08x "
1089 "got:%08x\n", __func__
,
1090 ch
->th_seq_num
+ 1, header
->th_seq_num
);
1094 grp
->out_of_sequence
= 0;
1095 ch
->th_seq_num
= header
->th_seq_num
;
1097 CTCM_PR_DBGDATA("ctcmpc: %s() FromVTAM_th_seq=%08x\n",
1098 __func__
, ch
->th_seq_num
);
1100 if (unlikely(fsm_getstate(grp
->fsm
) != MPCG_STATE_READY
))
1102 while ((pskb
->len
> 0) && !pdu_last_seen
) {
1103 curr_pdu
= (struct pdu
*)pskb
->data
;
1105 CTCM_PR_DBGDATA("%s: pdu_header\n", __func__
);
1106 CTCM_D3_DUMP((char *)pskb
->data
, PDU_HEADER_LENGTH
);
1107 CTCM_PR_DBGDATA("%s: pskb len: %04x \n",
1108 __func__
, pskb
->len
);
1110 skb_pull(pskb
, PDU_HEADER_LENGTH
);
1112 if (curr_pdu
->pdu_flag
& PDU_LAST
)
1114 if (curr_pdu
->pdu_flag
& PDU_CNTL
)
1115 pskb
->protocol
= htons(ETH_P_SNAP
);
1117 pskb
->protocol
= htons(ETH_P_SNA_DIX
);
1119 if ((pskb
->len
<= 0) || (pskb
->len
> ch
->max_bufsize
)) {
1120 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1121 "%s(%s): Dropping packet with "
1123 CTCM_FUNTAIL
, dev
->name
, pskb
->len
);
1125 priv
->stats
.rx_dropped
++;
1126 priv
->stats
.rx_length_errors
++;
1129 skb_reset_mac_header(pskb
);
1130 new_len
= curr_pdu
->pdu_offset
;
1131 CTCM_PR_DBGDATA("%s: new_len: %04x \n",
1133 if ((new_len
== 0) || (new_len
> pskb
->len
)) {
1134 /* should never happen */
1135 /* pskb len must be hosed...bail out */
1136 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1137 "%s(%s): non valid pdu_offset: %04x",
1138 /* "data may be lost", */
1139 CTCM_FUNTAIL
, dev
->name
, new_len
);
1142 skb
= __dev_alloc_skb(new_len
+4, GFP_ATOMIC
);
1145 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1146 "%s(%s): MEMORY allocation error",
1147 CTCM_FUNTAIL
, dev
->name
);
1148 priv
->stats
.rx_dropped
++;
1149 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1152 memcpy(skb_put(skb
, new_len
), pskb
->data
, new_len
);
1154 skb_reset_mac_header(skb
);
1155 skb
->dev
= pskb
->dev
;
1156 skb
->protocol
= pskb
->protocol
;
1157 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1158 *((__u32
*) skb_push(skb
, 4)) = ch
->pdu_seq
;
1161 if (do_debug_data
) {
1162 ctcm_pr_debug("%s: ToDCM_pdu_seq= %08x\n",
1163 __func__
, ch
->pdu_seq
);
1164 ctcm_pr_debug("%s: skb:%0lx "
1165 "skb len: %d \n", __func__
,
1166 (unsigned long)skb
, skb
->len
);
1167 ctcm_pr_debug("%s: up to 32 bytes "
1168 "of pdu_data sent\n", __func__
);
1169 ctcmpc_dump32((char *)skb
->data
, skb
->len
);
1173 sendrc
= netif_rx(skb
);
1174 priv
->stats
.rx_packets
++;
1175 priv
->stats
.rx_bytes
+= skblen
;
1176 skb_pull(pskb
, new_len
); /* point to next PDU */
1179 mpcginfo
= kmalloc(sizeof(struct mpcg_info
), gfp_type());
1180 if (mpcginfo
== NULL
)
1184 mpcginfo
->th
= header
;
1185 mpcginfo
->skb
= pskb
;
1186 CTCM_PR_DEBUG("%s: Not PDU - may be control pkt\n",
1189 sweep
= (struct th_sweep
*)pskb
->data
;
1190 mpcginfo
->sweep
= sweep
;
1191 if (header
->th_ch_flag
== TH_SWEEP_REQ
)
1192 mpc_rcvd_sweep_req(mpcginfo
);
1193 else if (header
->th_ch_flag
== TH_SWEEP_RESP
)
1194 mpc_rcvd_sweep_resp(mpcginfo
);
1195 else if (header
->th_blk_flag
== TH_DATA_IS_XID
) {
1196 struct xid2
*thisxid
= (struct xid2
*)pskb
->data
;
1197 skb_pull(pskb
, XID2_LENGTH
);
1198 mpcginfo
->xid
= thisxid
;
1199 fsm_event(grp
->fsm
, MPCG_EVENT_XID2
, mpcginfo
);
1200 } else if (header
->th_blk_flag
== TH_DISCONTACT
)
1201 fsm_event(grp
->fsm
, MPCG_EVENT_DISCONC
, mpcginfo
);
1202 else if (header
->th_seq_num
!= 0) {
1203 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1204 "%s(%s): control pkt expected\n",
1205 CTCM_FUNTAIL
, dev
->name
);
1206 priv
->stats
.rx_dropped
++;
1207 /* mpcginfo only used for non-data transfers */
1210 ctcmpc_dump_skb(pskb
, -8);
1215 dev_kfree_skb_any(pskb
);
1216 if (sendrc
== NET_RX_DROP
) {
1218 "The network backlog for %s is exceeded, "
1219 "package dropped\n", __func__
);
1220 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1223 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1224 __func__
, dev
->name
, ch
, ch
->id
);
1228 * tasklet helper for mpc's skb unpacking.
1230 * ch The channel to work on.
1231 * Allow flow control back pressure to occur here.
1232 * Throttling back channel can result in excessive
1233 * channel inactivity and system deact of channel
1235 void ctcmpc_bh(unsigned long thischan
)
1237 struct channel
*ch
= (struct channel
*)thischan
;
1238 struct sk_buff
*skb
;
1239 struct net_device
*dev
= ch
->netdev
;
1240 struct ctcm_priv
*priv
= dev
->ml_priv
;
1241 struct mpc_group
*grp
= priv
->mpcg
;
1243 CTCM_PR_DEBUG("%s cp:%i enter: %s() %s\n",
1244 dev
->name
, smp_processor_id(), __func__
, ch
->id
);
1245 /* caller has requested driver to throttle back */
1246 while ((fsm_getstate(grp
->fsm
) != MPCG_STATE_FLOWC
) &&
1247 (skb
= skb_dequeue(&ch
->io_queue
))) {
1248 ctcmpc_unpack_skb(ch
, skb
);
1249 if (grp
->out_of_sequence
> 20) {
1250 /* assume data loss has occurred if */
1251 /* missing seq_num for extended */
1252 /* period of time */
1253 grp
->out_of_sequence
= 0;
1254 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1257 if (skb
== skb_peek(&ch
->io_queue
))
1260 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1261 __func__
, dev
->name
, ch
, ch
->id
);
1266 * MPC Group Initializations
1268 struct mpc_group
*ctcmpc_init_mpc_group(struct ctcm_priv
*priv
)
1270 struct mpc_group
*grp
;
1272 CTCM_DBF_TEXT_(MPC_SETUP
, CTC_DBF_INFO
,
1273 "Enter %s(%p)", CTCM_FUNTAIL
, priv
);
1275 grp
= kzalloc(sizeof(struct mpc_group
), GFP_KERNEL
);
1279 grp
->fsm
= init_fsm("mpcg", mpcg_state_names
, mpcg_event_names
,
1280 MPCG_NR_STATES
, MPCG_NR_EVENTS
, mpcg_fsm
,
1281 mpcg_fsm_len
, GFP_KERNEL
);
1282 if (grp
->fsm
== NULL
) {
1287 fsm_newstate(grp
->fsm
, MPCG_STATE_RESET
);
1288 fsm_settimer(grp
->fsm
, &grp
->timer
);
1291 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT
, GFP_ATOMIC
| GFP_DMA
);
1292 if (grp
->xid_skb
== NULL
) {
1293 kfree_fsm(grp
->fsm
);
1297 /* base xid for all channels in group */
1298 grp
->xid_skb_data
= grp
->xid_skb
->data
;
1299 grp
->xid_th
= (struct th_header
*)grp
->xid_skb
->data
;
1300 memcpy(skb_put(grp
->xid_skb
, TH_HEADER_LENGTH
),
1301 &thnorm
, TH_HEADER_LENGTH
);
1303 grp
->xid
= (struct xid2
*)skb_tail_pointer(grp
->xid_skb
);
1304 memcpy(skb_put(grp
->xid_skb
, XID2_LENGTH
), &init_xid
, XID2_LENGTH
);
1305 grp
->xid
->xid2_adj_id
= jiffies
| 0xfff00000;
1306 grp
->xid
->xid2_sender_id
= jiffies
;
1308 grp
->xid_id
= skb_tail_pointer(grp
->xid_skb
);
1309 memcpy(skb_put(grp
->xid_skb
, 4), "VTAM", 4);
1312 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT
, GFP_ATOMIC
|GFP_DMA
);
1313 if (grp
->rcvd_xid_skb
== NULL
) {
1314 kfree_fsm(grp
->fsm
);
1315 dev_kfree_skb(grp
->xid_skb
);
1319 grp
->rcvd_xid_data
= grp
->rcvd_xid_skb
->data
;
1320 grp
->rcvd_xid_th
= (struct th_header
*)grp
->rcvd_xid_skb
->data
;
1321 memcpy(skb_put(grp
->rcvd_xid_skb
, TH_HEADER_LENGTH
),
1322 &thnorm
, TH_HEADER_LENGTH
);
1323 grp
->saved_xid2
= NULL
;
1324 priv
->xid
= grp
->xid
;
1330 * The MPC Group Station FSM
1334 * MPC Group Station FSM actions
1335 * CTCM_PROTO_MPC only
1339 * NOP action for statemachines
1341 static void mpc_action_nop(fsm_instance
*fi
, int event
, void *arg
)
1346 * invoked when the device transitions to dev_stopped
1347 * MPC will stop each individual channel if a single XID failure
1348 * occurs, or will intitiate all channels be stopped if a GROUP
1349 * level failure occurs.
1351 static void mpc_action_go_inop(fsm_instance
*fi
, int event
, void *arg
)
1353 struct net_device
*dev
= arg
;
1354 struct ctcm_priv
*priv
;
1355 struct mpc_group
*grp
;
1356 struct channel
*wch
;
1358 CTCM_PR_DEBUG("Enter %s: %s\n", __func__
, dev
->name
);
1360 priv
= dev
->ml_priv
;
1362 grp
->flow_off_called
= 0;
1363 fsm_deltimer(&grp
->timer
);
1364 if (grp
->channels_terminating
)
1367 grp
->channels_terminating
= 1;
1368 grp
->saved_state
= fsm_getstate(grp
->fsm
);
1369 fsm_newstate(grp
->fsm
, MPCG_STATE_INOP
);
1370 if (grp
->saved_state
> MPCG_STATE_XID7INITF
)
1371 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
1372 "%s(%s): MPC GROUP INOPERATIVE",
1373 CTCM_FUNTAIL
, dev
->name
);
1374 if ((grp
->saved_state
!= MPCG_STATE_RESET
) ||
1375 /* dealloc_channel has been called */
1376 (grp
->port_persist
== 0))
1377 fsm_deltimer(&priv
->restart_timer
);
1379 wch
= priv
->channel
[CTCM_WRITE
];
1381 switch (grp
->saved_state
) {
1382 case MPCG_STATE_RESET
:
1383 case MPCG_STATE_INOP
:
1384 case MPCG_STATE_XID2INITW
:
1385 case MPCG_STATE_XID0IOWAIT
:
1386 case MPCG_STATE_XID2INITX
:
1387 case MPCG_STATE_XID7INITW
:
1388 case MPCG_STATE_XID7INITX
:
1389 case MPCG_STATE_XID0IOWAIX
:
1390 case MPCG_STATE_XID7INITI
:
1391 case MPCG_STATE_XID7INITZ
:
1392 case MPCG_STATE_XID7INITF
:
1394 case MPCG_STATE_FLOWC
:
1395 case MPCG_STATE_READY
:
1397 tasklet_hi_schedule(&wch
->ch_disc_tasklet
);
1400 grp
->xid2_tgnum
= 0;
1401 grp
->group_max_buflen
= 0; /*min of all received */
1402 grp
->outstanding_xid2
= 0;
1403 grp
->outstanding_xid7
= 0;
1404 grp
->outstanding_xid7_p2
= 0;
1405 grp
->saved_xid2
= NULL
;
1407 grp
->changed_side
= 0;
1409 grp
->rcvd_xid_skb
->data
= grp
->rcvd_xid_data
;
1410 skb_reset_tail_pointer(grp
->rcvd_xid_skb
);
1411 grp
->rcvd_xid_skb
->len
= 0;
1412 grp
->rcvd_xid_th
= (struct th_header
*)grp
->rcvd_xid_skb
->data
;
1413 memcpy(skb_put(grp
->rcvd_xid_skb
, TH_HEADER_LENGTH
), &thnorm
,
1416 if (grp
->send_qllc_disc
== 1) {
1417 grp
->send_qllc_disc
= 0;
1418 mpc_send_qllc_discontact(dev
);
1421 /* DO NOT issue DEV_EVENT_STOP directly out of this code */
1422 /* This can result in INOP of VTAM PU due to halting of */
1423 /* outstanding IO which causes a sense to be returned */
1424 /* Only about 3 senses are allowed and then IOS/VTAM will*/
1425 /* become unreachable without manual intervention */
1426 if ((grp
->port_persist
== 1) || (grp
->alloc_called
)) {
1427 grp
->alloc_called
= 0;
1428 fsm_deltimer(&priv
->restart_timer
);
1429 fsm_addtimer(&priv
->restart_timer
, 500, DEV_EVENT_RESTART
, dev
);
1430 fsm_newstate(grp
->fsm
, MPCG_STATE_RESET
);
1431 if (grp
->saved_state
> MPCG_STATE_XID7INITF
)
1432 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_ALWAYS
,
1433 "%s(%s): MPC GROUP RECOVERY SCHEDULED",
1434 CTCM_FUNTAIL
, dev
->name
);
1436 fsm_deltimer(&priv
->restart_timer
);
1437 fsm_addtimer(&priv
->restart_timer
, 500, DEV_EVENT_STOP
, dev
);
1438 fsm_newstate(grp
->fsm
, MPCG_STATE_RESET
);
1439 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_ALWAYS
,
1440 "%s(%s): NO MPC GROUP RECOVERY ATTEMPTED",
1441 CTCM_FUNTAIL
, dev
->name
);
1446 * Handle mpc group action timeout.
1447 * MPC Group Station FSM action
1448 * CTCM_PROTO_MPC only
1450 * fi An instance of an mpc_group fsm.
1451 * event The event, just happened.
1452 * arg Generic pointer, casted from net_device * upon call.
1454 static void mpc_action_timeout(fsm_instance
*fi
, int event
, void *arg
)
1456 struct net_device
*dev
= arg
;
1457 struct ctcm_priv
*priv
;
1458 struct mpc_group
*grp
;
1459 struct channel
*wch
;
1460 struct channel
*rch
;
1462 priv
= dev
->ml_priv
;
1464 wch
= priv
->channel
[CTCM_WRITE
];
1465 rch
= priv
->channel
[CTCM_READ
];
1467 switch (fsm_getstate(grp
->fsm
)) {
1468 case MPCG_STATE_XID2INITW
:
1469 /* Unless there is outstanding IO on the */
1470 /* channel just return and wait for ATTN */
1471 /* interrupt to begin XID negotiations */
1472 if ((fsm_getstate(rch
->fsm
) == CH_XID0_PENDING
) &&
1473 (fsm_getstate(wch
->fsm
) == CH_XID0_PENDING
))
1476 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1479 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_DEBUG
,
1481 CTCM_FUNTAIL
, dev
->name
);
1486 * MPC Group Station FSM action
1487 * CTCM_PROTO_MPC only
1489 void mpc_action_discontact(fsm_instance
*fi
, int event
, void *arg
)
1491 struct mpcg_info
*mpcginfo
= arg
;
1492 struct channel
*ch
= mpcginfo
->ch
;
1493 struct net_device
*dev
;
1494 struct ctcm_priv
*priv
;
1495 struct mpc_group
*grp
;
1500 priv
= dev
->ml_priv
;
1502 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
1504 CTCM_FUNTAIL
, dev
->name
, ch
->id
);
1506 grp
->send_qllc_disc
= 1;
1507 fsm_event(grp
->fsm
, MPCG_EVENT_INOP
, dev
);
1516 * MPC Group Station - not part of FSM
1517 * CTCM_PROTO_MPC only
1518 * called from add_channel in ctcm_main.c
1520 void mpc_action_send_discontact(unsigned long thischan
)
1523 struct channel
*ch
= (struct channel
*)thischan
;
1524 unsigned long saveflags
= 0;
1526 spin_lock_irqsave(get_ccwdev_lock(ch
->cdev
), saveflags
);
1527 rc
= ccw_device_start(ch
->cdev
, &ch
->ccw
[15],
1528 (unsigned long)ch
, 0xff, 0);
1529 spin_unlock_irqrestore(get_ccwdev_lock(ch
->cdev
), saveflags
);
1532 ctcm_ccw_check_rc(ch
, rc
, (char *)__func__
);
1540 * helper function of mpc FSM
1541 * CTCM_PROTO_MPC only
1542 * mpc_action_rcvd_xid7
1544 static int mpc_validate_xid(struct mpcg_info
*mpcginfo
)
1546 struct channel
*ch
= mpcginfo
->ch
;
1547 struct net_device
*dev
= ch
->netdev
;
1548 struct ctcm_priv
*priv
= dev
->ml_priv
;
1549 struct mpc_group
*grp
= priv
->mpcg
;
1550 struct xid2
*xid
= mpcginfo
->xid
;
1554 int len
= TH_HEADER_LENGTH
+ PDU_HEADER_LENGTH
;
1556 CTCM_PR_DEBUG("Enter %s: xid=%p\n", __func__
, xid
);
1560 /* XID REJECTED: xid == NULL */
1561 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1562 "%s(%s): xid = NULL",
1563 CTCM_FUNTAIL
, ch
->id
);
1567 CTCM_D3_DUMP((char *)xid
, XID2_LENGTH
);
1569 /*the received direction should be the opposite of ours */
1570 if (((CHANNEL_DIRECTION(ch
->flags
) == CTCM_READ
) ? XID2_WRITE_SIDE
:
1571 XID2_READ_SIDE
) != xid
->xid2_dlc_type
) {
1573 /* XID REJECTED: r/w channel pairing mismatch */
1574 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1575 "%s(%s): r/w channel pairing mismatch",
1576 CTCM_FUNTAIL
, ch
->id
);
1580 if (xid
->xid2_dlc_type
== XID2_READ_SIDE
) {
1581 CTCM_PR_DEBUG("%s: grpmaxbuf:%d xid2buflen:%d\n", __func__
,
1582 grp
->group_max_buflen
, xid
->xid2_buf_len
);
1584 if (grp
->group_max_buflen
== 0 || grp
->group_max_buflen
>
1585 xid
->xid2_buf_len
- len
)
1586 grp
->group_max_buflen
= xid
->xid2_buf_len
- len
;
1589 if (grp
->saved_xid2
== NULL
) {
1591 (struct xid2
*)skb_tail_pointer(grp
->rcvd_xid_skb
);
1593 memcpy(skb_put(grp
->rcvd_xid_skb
,
1594 XID2_LENGTH
), xid
, XID2_LENGTH
);
1595 grp
->rcvd_xid_skb
->data
= grp
->rcvd_xid_data
;
1597 skb_reset_tail_pointer(grp
->rcvd_xid_skb
);
1598 grp
->rcvd_xid_skb
->len
= 0;
1600 /* convert two 32 bit numbers into 1 64 bit for id compare */
1601 our_id
= (__u64
)priv
->xid
->xid2_adj_id
;
1602 our_id
= our_id
<< 32;
1603 our_id
= our_id
+ priv
->xid
->xid2_sender_id
;
1604 their_id
= (__u64
)xid
->xid2_adj_id
;
1605 their_id
= their_id
<< 32;
1606 their_id
= their_id
+ xid
->xid2_sender_id
;
1607 /* lower id assume the xside role */
1608 if (our_id
< their_id
) {
1610 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
1611 "%s(%s): WE HAVE LOW ID - TAKE XSIDE",
1612 CTCM_FUNTAIL
, ch
->id
);
1615 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_NOTICE
,
1616 "%s(%s): WE HAVE HIGH ID - TAKE YSIDE",
1617 CTCM_FUNTAIL
, ch
->id
);
1621 if (xid
->xid2_flag4
!= grp
->saved_xid2
->xid2_flag4
) {
1623 /* XID REJECTED: xid flag byte4 mismatch */
1624 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1625 "%s(%s): xid flag byte4 mismatch",
1626 CTCM_FUNTAIL
, ch
->id
);
1628 if (xid
->xid2_flag2
== 0x40) {
1630 /* XID REJECTED - xid NOGOOD */
1631 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1632 "%s(%s): xid NOGOOD",
1633 CTCM_FUNTAIL
, ch
->id
);
1635 if (xid
->xid2_adj_id
!= grp
->saved_xid2
->xid2_adj_id
) {
1637 /* XID REJECTED - Adjacent Station ID Mismatch */
1638 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1639 "%s(%s): Adjacent Station ID Mismatch",
1640 CTCM_FUNTAIL
, ch
->id
);
1642 if (xid
->xid2_sender_id
!= grp
->saved_xid2
->xid2_sender_id
) {
1644 /* XID REJECTED - Sender Address Mismatch */
1645 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1646 "%s(%s): Sender Address Mismatch",
1647 CTCM_FUNTAIL
, ch
->id
);
1653 "The XID used in the MPC protocol is not valid, "
1655 priv
->xid
->xid2_flag2
= 0x40;
1656 grp
->saved_xid2
->xid2_flag2
= 0x40;
1663 * MPC Group Station FSM action
1664 * CTCM_PROTO_MPC only
1666 static void mpc_action_side_xid(fsm_instance
*fsm
, void *arg
, int side
)
1668 struct channel
*ch
= arg
;
1671 unsigned long saveflags
= 0; /* avoids compiler warning with
1672 spin_unlock_irqrestore */
1674 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1675 __func__
, smp_processor_id(), ch
, ch
->id
);
1677 if (ctcm_checkalloc_buffer(ch
))
1681 * skb data-buffer referencing:
1683 ch
->trans_skb
->data
= ch
->trans_skb_data
;
1684 skb_reset_tail_pointer(ch
->trans_skb
);
1685 ch
->trans_skb
->len
= 0;
1686 /* result of the previous 3 statements is NOT always
1687 * already set after ctcm_checkalloc_buffer
1688 * because of possible reuse of the trans_skb
1690 memset(ch
->trans_skb
->data
, 0, 16);
1691 ch
->rcvd_xid_th
= (struct th_header
*)ch
->trans_skb_data
;
1692 /* check is main purpose here: */
1693 skb_put(ch
->trans_skb
, TH_HEADER_LENGTH
);
1694 ch
->rcvd_xid
= (struct xid2
*)skb_tail_pointer(ch
->trans_skb
);
1695 /* check is main purpose here: */
1696 skb_put(ch
->trans_skb
, XID2_LENGTH
);
1697 ch
->rcvd_xid_id
= skb_tail_pointer(ch
->trans_skb
);
1698 /* cleanup back to startpoint */
1699 ch
->trans_skb
->data
= ch
->trans_skb_data
;
1700 skb_reset_tail_pointer(ch
->trans_skb
);
1701 ch
->trans_skb
->len
= 0;
1703 /* non-checking rewrite of above skb data-buffer referencing: */
1705 memset(ch->trans_skb->data, 0, 16);
1706 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1707 ch->rcvd_xid = (struct xid2 *)(ch->trans_skb_data + TH_HEADER_LENGTH);
1708 ch->rcvd_xid_id = ch->trans_skb_data + TH_HEADER_LENGTH + XID2_LENGTH;
1711 ch
->ccw
[8].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1712 ch
->ccw
[8].count
= 0;
1713 ch
->ccw
[8].cda
= 0x00;
1715 if (!(ch
->xid_th
&& ch
->xid
&& ch
->xid_id
))
1716 CTCM_DBF_TEXT_(MPC_TRACE
, CTC_DBF_INFO
,
1717 "%s(%s): xid_th=%p, xid=%p, xid_id=%p",
1718 CTCM_FUNTAIL
, ch
->id
, ch
->xid_th
, ch
->xid
, ch
->xid_id
);
1720 if (side
== XSIDE
) {
1721 /* mpc_action_xside_xid */
1722 if (ch
->xid_th
== NULL
)
1724 ch
->ccw
[9].cmd_code
= CCW_CMD_WRITE
;
1725 ch
->ccw
[9].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1726 ch
->ccw
[9].count
= TH_HEADER_LENGTH
;
1727 ch
->ccw
[9].cda
= virt_to_phys(ch
->xid_th
);
1729 if (ch
->xid
== NULL
)
1731 ch
->ccw
[10].cmd_code
= CCW_CMD_WRITE
;
1732 ch
->ccw
[10].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1733 ch
->ccw
[10].count
= XID2_LENGTH
;
1734 ch
->ccw
[10].cda
= virt_to_phys(ch
->xid
);
1736 ch
->ccw
[11].cmd_code
= CCW_CMD_READ
;
1737 ch
->ccw
[11].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1738 ch
->ccw
[11].count
= TH_HEADER_LENGTH
;
1739 ch
->ccw
[11].cda
= virt_to_phys(ch
->rcvd_xid_th
);
1741 ch
->ccw
[12].cmd_code
= CCW_CMD_READ
;
1742 ch
->ccw
[12].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1743 ch
->ccw
[12].count
= XID2_LENGTH
;
1744 ch
->ccw
[12].cda
= virt_to_phys(ch
->rcvd_xid
);
1746 ch
->ccw
[13].cmd_code
= CCW_CMD_READ
;
1747 ch
->ccw
[13].cda
= virt_to_phys(ch
->rcvd_xid_id
);
1749 } else { /* side == YSIDE : mpc_action_yside_xid */
1750 ch
->ccw
[9].cmd_code
= CCW_CMD_READ
;
1751 ch
->ccw
[9].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1752 ch
->ccw
[9].count
= TH_HEADER_LENGTH
;
1753 ch
->ccw
[9].cda
= virt_to_phys(ch
->rcvd_xid_th
);
1755 ch
->ccw
[10].cmd_code
= CCW_CMD_READ
;
1756 ch
->ccw
[10].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1757 ch
->ccw
[10].count
= XID2_LENGTH
;
1758 ch
->ccw
[10].cda
= virt_to_phys(ch
->rcvd_xid
);
1760 if (ch
->xid_th
== NULL
)
1762 ch
->ccw
[11].cmd_code
= CCW_CMD_WRITE
;
1763 ch
->ccw
[11].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1764 ch
->ccw
[11].count
= TH_HEADER_LENGTH
;
1765 ch
->ccw
[11].cda
= virt_to_phys(ch
->xid_th
);
1767 if (ch
->xid
== NULL
)
1769 ch
->ccw
[12].cmd_code
= CCW_CMD_WRITE
;
1770 ch
->ccw
[12].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1771 ch
->ccw
[12].count
= XID2_LENGTH
;
1772 ch
->ccw
[12].cda
= virt_to_phys(ch
->xid
);
1774 if (ch
->xid_id
== NULL
)
1776 ch
->ccw
[13].cmd_code
= CCW_CMD_WRITE
;
1777 ch
->ccw
[13].cda
= virt_to_phys(ch
->xid_id
);
1780 ch
->ccw
[13].flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1781 ch
->ccw
[13].count
= 4;
1783 ch
->ccw
[14].cmd_code
= CCW_CMD_NOOP
;
1784 ch
->ccw
[14].flags
= CCW_FLAG_SLI
;
1785 ch
->ccw
[14].count
= 0;
1786 ch
->ccw
[14].cda
= 0;
1788 CTCM_CCW_DUMP((char *)&ch
->ccw
[8], sizeof(struct ccw1
) * 7);
1789 CTCM_D3_DUMP((char *)ch
->xid_th
, TH_HEADER_LENGTH
);
1790 CTCM_D3_DUMP((char *)ch
->xid
, XID2_LENGTH
);
1791 CTCM_D3_DUMP((char *)ch
->xid_id
, 4);
1794 /* Such conditional locking is a known problem for
1795 * sparse because its static undeterministic.
1796 * Warnings should be ignored here. */
1797 spin_lock_irqsave(get_ccwdev_lock(ch
->cdev
), saveflags
);
1801 fsm_addtimer(&ch
->timer
, 5000 , CTC_EVENT_TIMER
, ch
);
1802 rc
= ccw_device_start(ch
->cdev
, &ch
->ccw
[8],
1803 (unsigned long)ch
, 0xff, 0);
1805 if (gotlock
) /* see remark above about conditional locking */
1806 spin_unlock_irqrestore(get_ccwdev_lock(ch
->cdev
), saveflags
);
1809 ctcm_ccw_check_rc(ch
, rc
,
1810 (side
== XSIDE
) ? "x-side XID" : "y-side XID");
1814 CTCM_PR_DEBUG("Exit %s: ch=0x%p id=%s\n",
1815 __func__
, ch
, ch
->id
);
1821 * MPC Group Station FSM action
1822 * CTCM_PROTO_MPC only
1824 static void mpc_action_xside_xid(fsm_instance
*fsm
, int event
, void *arg
)
1826 mpc_action_side_xid(fsm
, arg
, XSIDE
);
1830 * MPC Group Station FSM action
1831 * CTCM_PROTO_MPC only
1833 static void mpc_action_yside_xid(fsm_instance
*fsm
, int event
, void *arg
)
1835 mpc_action_side_xid(fsm
, arg
, YSIDE
);
1839 * MPC Group Station FSM action
1840 * CTCM_PROTO_MPC only
1842 static void mpc_action_doxid0(fsm_instance
*fsm
, int event
, void *arg
)
1844 struct channel
*ch
= arg
;
1845 struct net_device
*dev
= ch
->netdev
;
1846 struct ctcm_priv
*priv
= dev
->ml_priv
;
1847 struct mpc_group
*grp
= priv
->mpcg
;
1849 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1850 __func__
, smp_processor_id(), ch
, ch
->id
);
1852 if (ch
->xid
== NULL
) {
1853 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
1854 "%s(%s): ch->xid == NULL",
1855 CTCM_FUNTAIL
, dev
->name
);
1859 fsm_newstate(ch
->fsm
, CH_XID0_INPROGRESS
);
1861 ch
->xid
->xid2_option
= XID2_0
;
1863 switch (fsm_getstate(grp
->fsm
)) {
1864 case MPCG_STATE_XID2INITW
:
1865 case MPCG_STATE_XID2INITX
:
1866 ch
->ccw
[8].cmd_code
= CCW_CMD_SENSE_CMD
;
1868 case MPCG_STATE_XID0IOWAIT
:
1869 case MPCG_STATE_XID0IOWAIX
:
1870 ch
->ccw
[8].cmd_code
= CCW_CMD_WRITE_CTL
;
1874 fsm_event(grp
->fsm
, MPCG_EVENT_DOIO
, ch
);
1880 * MPC Group Station FSM action
1881 * CTCM_PROTO_MPC only
1883 static void mpc_action_doxid7(fsm_instance
*fsm
, int event
, void *arg
)
1885 struct net_device
*dev
= arg
;
1886 struct ctcm_priv
*priv
= dev
->ml_priv
;
1887 struct mpc_group
*grp
= NULL
;
1896 for (direction
= CTCM_READ
; direction
<= CTCM_WRITE
; direction
++) {
1897 struct channel
*ch
= priv
->channel
[direction
];
1898 struct xid2
*thisxid
= ch
->xid
;
1899 ch
->xid_skb
->data
= ch
->xid_skb_data
;
1900 skb_reset_tail_pointer(ch
->xid_skb
);
1901 ch
->xid_skb
->len
= 0;
1902 thisxid
->xid2_option
= XID2_7
;
1906 if (grp
->outstanding_xid7_p2
> 0) {
1907 if (grp
->roll
== YSIDE
) {
1908 if (fsm_getstate(ch
->fsm
) == CH_XID7_PENDING1
) {
1909 fsm_newstate(ch
->fsm
, CH_XID7_PENDING2
);
1910 ch
->ccw
[8].cmd_code
= CCW_CMD_SENSE_CMD
;
1911 memcpy(skb_put(ch
->xid_skb
,
1913 &thdummy
, TH_HEADER_LENGTH
);
1916 } else if (fsm_getstate(ch
->fsm
) < CH_XID7_PENDING2
) {
1917 fsm_newstate(ch
->fsm
, CH_XID7_PENDING2
);
1918 ch
->ccw
[8].cmd_code
= CCW_CMD_WRITE_CTL
;
1919 memcpy(skb_put(ch
->xid_skb
,
1921 &thnorm
, TH_HEADER_LENGTH
);
1926 if (grp
->roll
== YSIDE
) {
1927 if (fsm_getstate(ch
->fsm
) < CH_XID7_PENDING4
) {
1928 fsm_newstate(ch
->fsm
, CH_XID7_PENDING4
);
1929 memcpy(skb_put(ch
->xid_skb
,
1931 &thnorm
, TH_HEADER_LENGTH
);
1932 ch
->ccw
[8].cmd_code
= CCW_CMD_WRITE_CTL
;
1935 } else if (fsm_getstate(ch
->fsm
) == CH_XID7_PENDING3
) {
1936 fsm_newstate(ch
->fsm
, CH_XID7_PENDING4
);
1937 ch
->ccw
[8].cmd_code
= CCW_CMD_SENSE_CMD
;
1938 memcpy(skb_put(ch
->xid_skb
, TH_HEADER_LENGTH
),
1939 &thdummy
, TH_HEADER_LENGTH
);
1945 fsm_event(grp
->fsm
, MPCG_EVENT_DOIO
, ch
);
1952 * MPC Group Station FSM action
1953 * CTCM_PROTO_MPC only
1955 static void mpc_action_rcvd_xid0(fsm_instance
*fsm
, int event
, void *arg
)
1958 struct mpcg_info
*mpcginfo
= arg
;
1959 struct channel
*ch
= mpcginfo
->ch
;
1960 struct net_device
*dev
= ch
->netdev
;
1961 struct ctcm_priv
*priv
= dev
->ml_priv
;
1962 struct mpc_group
*grp
= priv
->mpcg
;
1964 CTCM_PR_DEBUG("%s: ch-id:%s xid2:%i xid7:%i xidt_p2:%i \n",
1965 __func__
, ch
->id
, grp
->outstanding_xid2
,
1966 grp
->outstanding_xid7
, grp
->outstanding_xid7_p2
);
1968 if (fsm_getstate(ch
->fsm
) < CH_XID7_PENDING
)
1969 fsm_newstate(ch
->fsm
, CH_XID7_PENDING
);
1971 grp
->outstanding_xid2
--;
1972 grp
->outstanding_xid7
++;
1973 grp
->outstanding_xid7_p2
++;
1975 /* must change state before validating xid to */
1976 /* properly handle interim interrupts received*/
1977 switch (fsm_getstate(grp
->fsm
)) {
1978 case MPCG_STATE_XID2INITW
:
1979 fsm_newstate(grp
->fsm
, MPCG_STATE_XID2INITX
);
1980 mpc_validate_xid(mpcginfo
);
1982 case MPCG_STATE_XID0IOWAIT
:
1983 fsm_newstate(grp
->fsm
, MPCG_STATE_XID0IOWAIX
);
1984 mpc_validate_xid(mpcginfo
);
1986 case MPCG_STATE_XID2INITX
:
1987 if (grp
->outstanding_xid2
== 0) {
1988 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITW
);
1989 mpc_validate_xid(mpcginfo
);
1990 fsm_event(grp
->fsm
, MPCG_EVENT_XID2DONE
, dev
);
1993 case MPCG_STATE_XID0IOWAIX
:
1994 if (grp
->outstanding_xid2
== 0) {
1995 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITI
);
1996 mpc_validate_xid(mpcginfo
);
1997 fsm_event(grp
->fsm
, MPCG_EVENT_XID2DONE
, dev
);
2003 CTCM_PR_DEBUG("ctcmpc:%s() %s xid2:%i xid7:%i xidt_p2:%i \n",
2004 __func__
, ch
->id
, grp
->outstanding_xid2
,
2005 grp
->outstanding_xid7
, grp
->outstanding_xid7_p2
);
2006 CTCM_PR_DEBUG("ctcmpc:%s() %s grpstate: %s chanstate: %s \n",
2008 fsm_getstate_str(grp
->fsm
), fsm_getstate_str(ch
->fsm
));
2015 * MPC Group Station FSM action
2016 * CTCM_PROTO_MPC only
2018 static void mpc_action_rcvd_xid7(fsm_instance
*fsm
, int event
, void *arg
)
2020 struct mpcg_info
*mpcginfo
= arg
;
2021 struct channel
*ch
= mpcginfo
->ch
;
2022 struct net_device
*dev
= ch
->netdev
;
2023 struct ctcm_priv
*priv
= dev
->ml_priv
;
2024 struct mpc_group
*grp
= priv
->mpcg
;
2026 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
2027 __func__
, smp_processor_id(), ch
, ch
->id
);
2028 CTCM_PR_DEBUG("%s: outstanding_xid7: %i, outstanding_xid7_p2: %i\n",
2029 __func__
, grp
->outstanding_xid7
, grp
->outstanding_xid7_p2
);
2031 grp
->outstanding_xid7
--;
2032 ch
->xid_skb
->data
= ch
->xid_skb_data
;
2033 skb_reset_tail_pointer(ch
->xid_skb
);
2034 ch
->xid_skb
->len
= 0;
2036 switch (fsm_getstate(grp
->fsm
)) {
2037 case MPCG_STATE_XID7INITI
:
2038 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITZ
);
2039 mpc_validate_xid(mpcginfo
);
2041 case MPCG_STATE_XID7INITW
:
2042 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITX
);
2043 mpc_validate_xid(mpcginfo
);
2045 case MPCG_STATE_XID7INITZ
:
2046 case MPCG_STATE_XID7INITX
:
2047 if (grp
->outstanding_xid7
== 0) {
2048 if (grp
->outstanding_xid7_p2
> 0) {
2049 grp
->outstanding_xid7
=
2050 grp
->outstanding_xid7_p2
;
2051 grp
->outstanding_xid7_p2
= 0;
2053 fsm_newstate(grp
->fsm
, MPCG_STATE_XID7INITF
);
2055 mpc_validate_xid(mpcginfo
);
2056 fsm_event(grp
->fsm
, MPCG_EVENT_XID7DONE
, dev
);
2059 mpc_validate_xid(mpcginfo
);
2067 * mpc_action helper of an MPC Group Station FSM action
2068 * CTCM_PROTO_MPC only
2070 static int mpc_send_qllc_discontact(struct net_device
*dev
)
2073 struct sk_buff
*skb
;
2074 struct qllc
*qllcptr
;
2075 struct ctcm_priv
*priv
= dev
->ml_priv
;
2076 struct mpc_group
*grp
= priv
->mpcg
;
2078 CTCM_PR_DEBUG("%s: GROUP STATE: %s\n",
2079 __func__
, mpcg_state_names
[grp
->saved_state
]);
2081 switch (grp
->saved_state
) {
2083 * establish conn callback function is
2084 * preferred method to report failure
2086 case MPCG_STATE_XID0IOWAIT
:
2087 case MPCG_STATE_XID0IOWAIX
:
2088 case MPCG_STATE_XID7INITI
:
2089 case MPCG_STATE_XID7INITZ
:
2090 case MPCG_STATE_XID2INITW
:
2091 case MPCG_STATE_XID2INITX
:
2092 case MPCG_STATE_XID7INITW
:
2093 case MPCG_STATE_XID7INITX
:
2094 if (grp
->estconnfunc
) {
2095 grp
->estconnfunc(grp
->port_num
, -1, 0);
2096 grp
->estconnfunc
= NULL
;
2099 case MPCG_STATE_FLOWC
:
2100 case MPCG_STATE_READY
:
2101 grp
->send_qllc_disc
= 2;
2102 new_len
= sizeof(struct qllc
);
2103 qllcptr
= kzalloc(new_len
, gfp_type() | GFP_DMA
);
2104 if (qllcptr
== NULL
) {
2105 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
2106 "%s(%s): qllcptr allocation error",
2107 CTCM_FUNTAIL
, dev
->name
);
2111 qllcptr
->qllc_address
= 0xcc;
2112 qllcptr
->qllc_commands
= 0x03;
2114 skb
= __dev_alloc_skb(new_len
, GFP_ATOMIC
);
2117 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
2118 "%s(%s): skb allocation error",
2119 CTCM_FUNTAIL
, dev
->name
);
2120 priv
->stats
.rx_dropped
++;
2125 memcpy(skb_put(skb
, new_len
), qllcptr
, new_len
);
2128 if (skb_headroom(skb
) < 4) {
2129 CTCM_DBF_TEXT_(MPC_ERROR
, CTC_DBF_ERROR
,
2130 "%s(%s): skb_headroom error",
2131 CTCM_FUNTAIL
, dev
->name
);
2132 dev_kfree_skb_any(skb
);
2136 *((__u32
*)skb_push(skb
, 4)) =
2137 priv
->channel
[CTCM_READ
]->pdu_seq
;
2138 priv
->channel
[CTCM_READ
]->pdu_seq
++;
2139 CTCM_PR_DBGDATA("ctcmpc: %s ToDCM_pdu_seq= %08x\n",
2140 __func__
, priv
->channel
[CTCM_READ
]->pdu_seq
);
2142 /* receipt of CC03 resets anticipated sequence number on
2144 priv
->channel
[CTCM_READ
]->pdu_seq
= 0x00;
2145 skb_reset_mac_header(skb
);
2147 skb
->protocol
= htons(ETH_P_SNAP
);
2148 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2150 CTCM_D3_DUMP(skb
->data
, (sizeof(struct qllc
) + 4));
2161 /* --- This is the END my friend --- */